lilypond-user
[Top][All Lists]
Advanced

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

Re: scheme with Frescobaldi


From: Urs Liska
Subject: Re: scheme with Frescobaldi
Date: Tue, 26 Jun 2018 10:45:42 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0



Am 26.06.2018 um 02:25 schrieb Freeman Gilmore:

On Mon, Jun 25, 2018 at 4:04 PM, Urs Liska <address@hidden> wrote:

CCing to the list.


Am 25.06.2018 um 21:47 schrieb Freeman Gilmore:


On Mon, Jun 25, 2018 at 9:29 AM, Urs Liska <address@hidden> wrote:

Hi Freeman,


Am 25.06.2018 um 15:03 schrieb Freeman Gilmore:
​Can scheme alone be used in Frescobaldi (or scheme sandbox)?


It's not clear to me what you want ot achieve.

The Scheme sandbox is surely not available in Frescobaldi.

You can of course write LilyPond files that exclusively contain Scheme code, and that code doesn't have to be related to scores. But at least the entry point must be LilyPond language.

Try this file:
\version "2.19.80"

#(let
  ((something 'something-else))
  (display something)
  (newline)
  (display something)(display something))
It will do in Scheme what you tell it, and from there you have access to anything you can do with Guile Scheme (and the LilyPond environment set up automatically).

That will give you syntax highlighting and auto-indentation from Frescobaldi (much better than the Scheme sandbox) but no immediate _expression_ evaluation.

HTH
Urs

 thank you,
ƒg
Thanks Urs:

That worked.   Problem was that I did not know that the results would be displayed in the log window.   The tutorial I am using had some example like  (+ 1 2 3)  =>  and I was expecting 6 in the same window on the next line when I compiled.

This is what one refers to as a REPL (read-eval-print-loop), which is what LilyPond's Scheme sandbox does.

  This may be what you mean by " but no immediate _expression_ evaluation". 

Yes. Frescobaldi deals with LilyPond *files*, not an immediate _expression_ evaluation.

Is => valid in guile?  

No.

 How would I display the results of (+ 1 2 3), at this point of the tutorial it just says  "(+ 1 2 3)  =>   6"?

When a tutorial writes "=>" it means: "You type in '(+ 1 2 3)', and the REPL will display '6'. So "=>" isn't a syntactical construct but a typographical convention for "the _expression_ to the left evaluates to the datum on the right".

Tutorials usually want you to learn from this immediate evaluation, and in Frescobaldi you have to always do that extra step to display something. But in general it's worth the effort, and I do that 90% of the time when I want to try something out or learn more about Scheme.

​​
For displaying values you can use #(display) or #(ly:message "Some value: ~a" data) (to start with ...)

HTH
Urs


Thank you,
ƒg
​Urs:

In you first example #(let...) what function does 'let' preform?    From your examples in "​For displaying values you can use #(display) or #(ly:message "Some value: ~a" data) (to start with ...)", could you please give me examples of each?   I need this to study the tutorial using Frescobaldi.

OK, it probably wasn't such a good idea to use non-atomic examples.
Let me try to put it another way: what you have in Frescobaldi is a LilyPond file. This file may include Scheme code, and LilyPond even works if there is *only* Scheme code in the file and no score is even generated. That way you can use LilyPond and Frescobaldi as a tool to experiment with Scheme code.

The way to include Scheme in LilyPond is the '#'. Whenever LilyPond encounters this hash it will have the immediately following _expression_ evaluated by Scheme. Essentially the _expression_ is replaced by the resulting value.

What you have already noticed is that this Scheme code is not evaluated immediately (as is done on a REPL and what your tutorial seems to assume), but only when compiling the LilyPond file.

One more thing to understand is the following: any Scheme _expression_ *evaluates to* something (like (+ 1 2 3) evaluates to 6). In a REPL this value is displayed but in LilyPond/Frescobaldi it is not. If you write #(+ 1 2 3) in a LilyPond file it *will* evaluate to 6 but it only has the effect of placing that value 6 in the LilyPond file, which will have no effect at all.

The additional effort you have to make is explicitly print any value you want to inspect to the log window. Scheme provides some functions for that purpose: display, print, pretty-print, and more.
  #(define my-var 12)
  #(display my-var)
will print '12' to the log window,
  #(display (+ 1 2 3))
will print '6'

Note that display won't add a line break, so when you want to see more than one value you'll want to add #(newline) expressions in between.

A final remark: there are many Scheme implementations (or dialects) around, with more or less subtle differences. When you use LilyPond you have a very specific dialect available (the Guile implementation in its version 1.8), plus when starting up LilyPond a number of extra Guile modules and many LilyPond features are automatically added. This means that when you follow a "Scheme tutorial" not necessarily everything will match what you find in LilyPond.

[And please allow me a plug: you may find rewarding to have a look at https://scheme-book.ursliska.de, which is far from complete but aims at giving a slow-paced and detailed introduction specifically from a LilyPond perspective]

Best
Urs


​Thank you,
ƒg​
 
         
​​
              


reply via email to

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