lilypond-user
[Top][All Lists]
Advanced

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

Re: guitar scale diagram - change root


From: bart deruyter
Subject: Re: guitar scale diagram - change root
Date: Fri, 2 Sep 2016 08:26:47 +0200

Hey,

thanks for the help and I think I understand the explanation about Lisp.

I thought it would be something like this though, the error message made me think that scheme wasn't able to read the variable,  I only did not know why, now I do :-) .

Another problem for me is having usecases to learn scheme. I mean, I can read other code and learn from it, but it doesn't let you think in a 'problem-solving' way because the solution already is there.

I learn best by having something concrete, like the above and ponder about it to add new things. That way, I won't forget the solution because of the effort I've put into it and because of the research I've put into it. 
It's not productive at all to begin, but it does train your mind to think as a computer, which in my experience does make it productive in the end.

It's strange to say, but lilypond is so good that most often scheme is not needed, which makes the actual use of scheme rare (for me at least), which in turn does not let me train it :-) .

Now I'll (lily)ponder on :-)

grtz,
Bart


2016-09-01 21:16 GMT+02:00 David Kastrup <address@hidden>:
bart deruyter <address@hidden> writes:

> #(define-markup-command (scale-diagramm layout props arg1 arg2 start arg3
> arg4) (list? integer? integer? number? integer?)
>
> (interpret-markup layout props
>
>     (markup
>
>      (#:override (cons 'size arg3 )
>
> (#:override '(fret-diagram-details
>                     . (
>                        (finger-code . in-dot)
>                        (number-type . arabic)
>                        (label-dir   . -1)
>                        (orientation . landscape)
>                        (dot-radius  . 0.4)
>                        (fret-count . arg4 )
>                        (top-fret-thickness . 4)))
>          #:fret-diagram-verbose
>         (fret-from-list arg1 '() arg2 start ))))))
>
> but then I get this error:
>
> Preprocessing graphical objects...fret-diagrams.scm <0>: In procedure > in
> _expression_ (> maxfret my-fret-count):
>
> fret-diagrams.scm <1>: Wrong type argument in position 2: arg4
>
>
> Clearly it's an issue of 'type argument'. When I change fret-count to the
> actual integer 12 instead of the variable arg4, it works. It is probably
> something schemy I don't get...

arg4 is a symbol in a quoted list, just like landscape, arabic, in-dot
are.  If you replace the quote ' after #:override with a "quasiquote",
namely the backward tick ` then you can "unquote" inside of the
_expression_ by preceding something with , the unquote character.  When
an _expression_ is unquoted, it is evaluated as normal and placed in the
quoted list.  So you'd have
(#:override `(fret-diagram-details
                  [...]
                  (fret-count . ,arg4)
                  [...]

Lisp (and Scheme) do not actually have a program syntax.  Instead you
enter the parse tree as a data structure, a nested list.  Every start of
a list is a function call, every symbol is looked up as a variable
(functions are just special variable values) and the remaining list
elements are the argument of the function call, evaluated before
calling.  Or, in case we are talking about a macro (or special form)
instead of a function, passed unevaluated to the macro and the result of
the macro call is then evaluated.

That sounds awfully complex, but that's all there is to Scheme program
structure.  The only "syntax" you have to deal with is actually for data
entry, most of which consists of lists.

Once you realise that Scheme does not have a program syntax, just a
program _structure_ and that the syntax is only for data entry, it
becomes obvious
a) why Scheme feels so different from other languages
b) why it is so great for macro/program manipulation

--
David Kastrup


reply via email to

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