Am Mo., 8. Apr. 2019 um 10:07 Uhr schrieb Gianmaria Lari
<address@hidden>:
>
> I try to explain what I'm trying to do.
>
> I want some functions helping me to numbering exercise like this:
>
> 1
> 2
> 3
> 3.1
> 3.2
> 3.3
> 4
> 4.1
> 4.2
>
> etc.
> I thought that an alternative approach that looks nice to try but it's over-engineering would be to create a single function able to do the work of the three functions according to a parameter. Something like
>
>
> #(define (indenter operation l) .....)
>
>
> if the "operation" argument is "inc" the indenter function has to inc, if the "operation" argument is "indent" the indenter function has to indent etc. I hope I have been clear.
> This solution is nice because encapsulate all - data and structure - and has no problem to modify the list that would be a local persistent data (I don't remember how you call it in scheme).
>
How about:
foo =
#(let ((x (cons 1 0)))
(define-scheme-function (arg)(symbol?)
(case arg
((indent) (set! x (cons (car x) (1+ (cdr x)))))
((increase) (set! x (cons (1+ (car x)) 0)))
((reset) (set! x (cons 1 0))))
(if (zero? (cdr x))
(format #f "~a" (car x))
(format #f "~a.~a" (car x) (cdr x)))))
\markup \foo #'start
\markup \foo #'indent
\markup \foo #'indent
\markup \foo #'indent
\markup \foo #'increase
\markup \foo #'indent
\markup \foo #'indent
\markup \foo #'indent
\markup \foo #'reset
\markup \foo #'indent
\markup \foo #'increase
\markup \foo #'indent
it's a bit different from what I wanted but I think there is all the things I need to make what I prefer. Thanks a lot Harm!
It will take some time to understand it all. I'm studying it :)
Ciao, g.