Hi Anders,

On Thu, Mar 5, 2015 at 1:42 PM, <anders.vin...@bek.no> wrote:

> >>>>> "D" == David Nalesnik writes:
>
>     D> What you are suggesting seems to be analogous to what is already
>     D> done for the functions on the Scheme functions documentation page
>     D> I referenced earlier.
>
> Ah, but you've got all you need there already it seems.
>
> 'procedure-source will return the body of any defined function, then
> just grab the cadr of this to get the lambda-list:
>
> (define (get-proc-args proc)
>   (cons (procedure-name proc) (cadr (procedure-source proc))))
>
> (begin
>   (newline)
>   (display (get-proc-args get-chord-shape))
>   (newline)
>   (display (procedure-source get-proc-args)))
>
> will return :
>
> (get-chord-shape shape-code tuning base-chord-shapes)
> (lambda (proc) (cons (procedure-name proc) (cadr (procedure-source proc))))
>
>
I like the approach with the macro because then it is easy to mark certain
functions as receiving documentation.

The other alternative would be to provide a list of functions to document.

The first option is nice because we look in one place in the code to see
that it's a documented function, whereas in the second approach, there is
some list in some other file to consider.

____

Trying to experiment with the macros you provided earlier is giving me some
trouble.

Within an LY file this works just fine:

%%%%%%%%%%%%%
\version "2.19.16"

#(use-modules (ice-9 syncase))
%#(use-syntax (ice-9 syncase))

#(define procargstable '())

#(let-syntax ((defineS
               (syntax-rules ()
                 ((defineS (proc . args) body)
                  (begin
                   (set! procargstable (cons '(proc args) procargstable))
                   (define (proc . args) body))))))
   (defineS (foo a b)
     (+ a b)))

#(format #t "table: ~a~%(foo 1 2) ==> ~a~%" procargstable (foo 1 2))
%%%%%%%%%%%%%

However, this does not work:

%%%%%%%%%%%%%
\version "2.19.16"

#(use-modules (ice-9 syncase))

#(define procargstable '())

#(define-syntax defineS
   (syntax-rules ()
     ((defineS (proc . args) body)
      (begin
       (set! procargstable (cons '(proc args) procargstable))
       (define (proc . args) body)))))
%%%%%%%%%%%%%%%

I get the following output:

[...] error: GUILE signaled an error for the expression beginning here

#

(define-syntax defineS

Wrong type to apply: #<Music function #<procedure #f (parser location arg)>>

fatal error: failed files:
"c:\\users\\david\\appdata\\local\\temp\\frescobaldi-4kllxf\\tmpma8ecw\\
let-syntax.ly"

Exited with return code 1.




I am able to use the define-syntax form within scm/output-lib.scm, but I
get the same sort of error when the name of the new function conflicts with
a name already in use, as when I try to define the function 'bar' you
provided in your example.


I don't understand what is happening when I attempt to define the macro in
the LY file, though.


Best,

David
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to