Scheme learning

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Scheme learning

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:


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



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


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


Many other references and material can be found at:


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.






_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme learning

Helge Kruse-4
Am 27.05.2018 um 13:38 schrieb Andrew Bernard:
> 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:
>
> [list of resources]

Hey Andrew,

These resources can be read online. Do you know any ebook resources,
e.g. in epub format? While traveling the train it would be worth to use
the time to learn.

Regards,
Helge

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme learning

Hans Åberg-2

> On 27 May 2018, at 14:13, Helge Kruse <[hidden email]> wrote:
>
> Am 27.05.2018 um 13:38 schrieb Andrew Bernard:
>> 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:
>
> These resources can be read online. Do you know any ebook resources,
> e.g. in epub format? While traveling the train it would be worth to use
> the time to learn.

HTML can be recursively downloaded using wget [1]. Searching for "sicp pdf" gives links such as [2].

1. https://en.wikipedia.org/wiki/Wget
2. https://github.com/sarabander/sicp-pdf



_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme learning

Robert Schmaus
In reply to this post by Andrew Bernard
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.
>
>
>
>
>

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme learning

David Kastrup
Robert Schmaus <[hidden email]> writes:

> 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.

Given a context x, evaluated at the time where the \applyContext call is
"iterated".

> But how do I get it outside the lambda thing?

There is no current bar number outside of iteration (the interpretation
of a music expression in the sequence of musical time).

> 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

You can use set! for setting global variables (to be defined at global
scope) but it seems nonsensical to store stuff in a variable instead of
just setting that property.

So something like
\applyContext
  #(lambda (current-context)
    (set! (ly:context-property (ly:context-find current-context 'Score)
                               'currentBarNumber)
          (ly:context-property current-context 'currentBarNumber)))


> 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

Well, \applyContext and \set are called at the same point of musical
time.  \set is worked on during the start of time step (so that the
settings it establishes are present for other commands) while
\applyContext has its workload defined for the "process-music" stage.
Which means that stuff like the Timing_translator have already run.
Also, \set has completed.  Probably not the most intuitive behavior.

Not actually related to Scheme but rather to the order LilyPond
internals process music.

> 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.

Well, to be fair, in this particular case I'll readily admit that
"obvious" is not really a proper description of what happens.

Most of what you guessed was quite right but you weren't able to
appreciate that because of the final spanner in the works (the execution
order) that had rather little to do with your deductions.

> 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 ...

It won't help for the quirks of this particular case.  I admit I looked
in the code for the details of \applyContext, mostly because I am too
lazy to look in places I know my way around less.

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme learning

Hans Åberg-2
In reply to this post by Robert Schmaus

> On 28 May 2018, at 21:47, Robert Schmaus <[hidden email]> wrote:
>
> 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?

The lambda comes from the book by Alonzo Church, "The Calculi of Lambda-conversion", which is a logic theory about function applications, but it is unknown why he choose the letter lambda, though a prefix notation makes it easier to carry out formal proofs. It then caught on in the computer community.

Instead of a prefix lambda notation, one can use the infix "mapsto" notation, and there are some examples here:
  https://en.wikipedia.org/wiki/Lambda_calculus



_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme learning

Torsten Hämmerle
Hans Åberg-2 wrote
> The lambda comes from the book by Alonzo Church, "The Calculi of
> Lambda-conversion", which is a logic theory about function applications,
> but it is unknown why he choose the letter lambda, though a prefix
> notation makes it easier to carry out formal proofs. It then caught on in
> the computer community.

As far as I know, Church originally used a "hat" accent ^.
From there, it's not far to a Greek Λ and its lower-case form λ.

All the best,
Torsten



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme learning

Hans Åberg-2

> On 28 May 2018, at 23:48, Torsten Hämmerle <[hidden email]> wrote:
>
> As far as I know, Church originally used a "hat" accent ^.
> From there, it's not far to a Greek Λ and its lower-case form λ.

In [1], p. 7, there is a remark that he originally stated that, but later said the choice was more accidental, a symbol was needed, and λ happened to be chosen.

1. https://github.com/aistrate/Articles/blob/master/Haskell/History%20of%20Lambda-calculus%20and%20Combinatory%20Logic%20(Cardone%2C%20Hindley).pdf



_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user