lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme learning


From: Robert Schmaus
Subject: Re: Scheme learning
Date: Mon, 28 May 2018 21:47:09 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

Hi Andrew,

thanks first of all for your mail and the many resources (which I will need some time to look through, I think) ... and sorry for the late reply, I had two computer-free days, which sometimes really is refreshing.

I agree with you - when I looked at the Scheme functions (mainly as Snippets) I saw that it's not very complicated. It was just when I tried to customise something that I really had to do a lot of guesswork how to get this to work. Does this expression return something or not? What does "lambda" mean, why does this expression need a context and where do I get it from?

Just to illustrate what I mean: To get a bar number, one needs to use the apply context function. In the documentation, there's this:

\applyContext
  #(lambda (x)
    (format #t "\nWe were called in barnumber ~a.\n"
     (ly:context-property x 'currentBarNumber)))

So, (ly:context-property x 'currentBarNumber) returns the bar number, clear enough. But how do I get it outside the lambda thing? Replacing the format directive with a define directive doesn't work because bnum is not know outside.

\applyContext
  #(lambda (x)
    (define bnum (ly:context-property x 'currentBarNumber)))
\set Score.currentBarNumber = #bnum

Defining the variable outside and assigning a value inside throws no error but the value in the last line is 0

#(define bnum 0)
\applyContext
  #(lambda (x)
    (set! bnum (ly:context-property x 'currentBarNumber)))
\set Score.currentBarNumber = #bnum

In this way, I fiddle around, sometimes I got it to work sometimes not and in either case I don't really have a clue why.

So anyway, as you might have seen, Urs sent me a link to a lilypond-specific Scheme manual that he started - I guess I'll work my way through that (as well as the "Extending Lilypond" manual) first. Maybe then I'm even really hooked to see more of Scheme, who knows ...

That Scheme people are a frienly lot is something I noticed right away!
So thanks again for your encouragement and resources - I really appreciate it!

Best,
Robert

PS "Teach Youself Scheme in Fixnum Days" is a great title, by the way ...



Am 27.05.18 um 13:38 schrieb Andrew Bernard:
Hi Robert,

I've started a new thread on the topic under discussion of the difficulty of learning Scheme. This comes up frequently. Putting my programmer hat on, it's a common experience for programmers brought up in C family languages to be baffled and daunted by Scheme and Lisp family languages. But it's worth noting that MIT taught Scheme as the fundamental undergraduate computer language for many, many years. This is because the insight Scheme gives one into computer science thinking is really valuable, no matter what language you may go on to later. MIT sadly now teaches Python instead. There are a large number of people that regard this as a mistake and a decline in educational quality, mere vocational training.

The thing about Lisp and Scheme is that there is so little syntax that you can pick it up in an hour. As for all the nested parentheses, any decent editor (ahem, emacs...) handles the brackets and indenting for you, leading to readable code and ease of typing. It;s the conceptual shift that people find difficult. But really, putting in an initial effort invariably leads to an epiphany related by all Lisp programmers, where one day you just _get it_. It's an interesting experience. After that, you regard the world differently.

The fantastic thing about lilypond is that it is extensible with Scheme, and that makes Scheme definitely worth learning of you want to do sophisticated things with lilypond. GNU had a concept of use Scheme as an extension language for its whole ecosystem, and this is why Guile was created. This never really took off, but lilypond is one of the shining examples of this GNU concept.

Scheme as Guile in the context of lilypond can be complex, because it is a highly domain specific environment, but Scheme people are a friendly lot in general and there are many learned colleagues on the list willing to help, and there are no stupid questions (except maybe those lacking an MWE :-)). I really feel the investment in time improves your work in non Lisp languages, gives you a foothold in Functional Programming, and allows you to take the out of the box already superb lilypond output to even more refined heights. I cant think of any downside except the time invested - but it's just so worthwhile.

As to learning materials, each person will have their own recommendations. I would recommend obtaining a copy of SICP, Structure and Interpretation of Computer Programs, by Ableson and Sussman, the MIT text and classic of computer science. This is the famous Wizard book, from the cover picture. My hardback copy sits on my bookshelf near me just to give daily inspiration. Although out of print, the full text is available on the web:

https://mitpress.mit.edu/sites/default/files/sicp/index.html

Amazingly, MIT has released films of Sussman himself teaching MIT 6.001 in 1986. Highly recommended.

https://ds26gte.github.io/tyscheme/


For a quick introduction, there's Teach Youself Scheme in Fixnum Days, by Dorai Sitaram:

https://ds26gte.github.io/tyscheme/

Also recommended is The Scheme Programming Language by Kent Dybvig, also online:

https://scheme.com/tspl4/

Many other references and material can be found at:

http://schemers.org/

Andrew

As a footnote, I would not recommend learning Scheme for lilypond via Racket. Racket is a great Lisp dialect, but it is so extensively extended compared to Scheme that all the nice things you learn generally can't be applied, so it just gets frustrating in our context. But they have great documentation.








reply via email to

[Prev in Thread] Current Thread [Next in Thread]