Re: Attaching an alist to a grob

2015-01-15 Thread Urs Liska


Am 14.01.2015 um 14:47 schrieb Mattes:
  
Am Mittwoch, 14. Januar 2015 13:56 CET, Urs Liska u...@openlilylib.org schrieb:
  

OK, I see.
But somehow it feels wrong that

#(display annotation? some-obj)

doesn't produce #t but the content of location.
Should I ignore that feeling?

If you intended to write

  #(display (annotation? some-obj))


Oops, yes, that's what I intended to write in the above message.
Of course that's not what I'd write in real code where I'd only need 
#(if (annotation? some-obj)).


then, yes, ignore that feeling. Scheme, like all Lisps (that I know of)  has 
generalized booleans,
so anything that's not explicitly false [1] is considered true. Because of this 
you hardly ever see
a litteral #t in Scheme code.


OK. I'll try to internalize this, and of course I'll update the code ASAP.

Thanks again for the different input
Urs



  Cheers, RalfD

[1] while Scheme considers #f to be the only _false_ value, Common Lisp et al. 
also consider
   the empty list '() as a valse value.



Urs

  
  
  
  




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


Re: Attaching an alist to a grob

2015-01-14 Thread Urs Liska


Am 14.01.2015 um 04:08 schrieb Paul Morris:

Urs Liska wrote

Now I've checked - it's perfect. Thank you again!

There is no alist? predicate, but it's very easy to define:

#(define (alist? lst)
 (and (list? lst)
(every pair? lst)))

Glad to help and glad someone else is benefiting from this.  (On a related
note, I also worked out how to create custom context properties if that's
ever useful.)


Currently this doesn't ring a bell with me but I can imagine I'll come 
back to this one day.




Hey, look at you slinging that Scheme like it was nothing!  ;-)


Yes, I made some surprising progress with Scheme recently. I didn't even 
get stuck in the ands and parens in the actual predicate I wrote


#(define (annotation? obj)
   (and
(and (list? obj)
 (every pair? obj))
(and (if (assoc-ref obj type) #t #f)
 (if (assoc-ref obj location) #t #f

:-)

Unfortunately that does *not* mean there are no huge mysteries left ...

Urs



Cheers,
-Paul





--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Attaching-an-alist-to-a-grob-tp170412p170434.html
Sent from the User mailing list archive at Nabble.com.

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



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


Re: Attaching an alist to a grob

2015-01-14 Thread Urs Liska


Am 14.01.2015 um 11:18 schrieb Mattes:
  
Am Mittwoch, 14. Januar 2015 09:42 CET, Urs Liska u...@openlilylib.org schrieb:
  

Yes, I made some surprising progress with Scheme recently. I didn't even
get stuck in the ands and parens in the actual predicate I wrote

#(define (annotation? obj)
 (and
  (and (list? obj)
   (every pair? obj))
  (and (if (assoc-ref obj type) #t #f)
   (if (assoc-ref obj location) #t #f

Proper indentation helps ;-)
But why so contrived? Your code is equivalent to:

#(define (annotation? obj)
(and
 (list? obj)
 (every pair? obj)
 (if (assoc-ref obj type) #t #f)
 (if (assoc-ref obj location) #t #f)))

HTH Ralf Mattes
  
  



Thanks, this is of course better.
sorting out nested conditionals has never been my strongest point ;-)

Urs

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


Re: Attaching an alist to a grob

2015-01-14 Thread Richard Shann
On Wed, 2015-01-14 at 12:34 +0100, Urs Liska wrote:
 Am 14.01.2015 um 12:28 schrieb Richard Shann:
  On Wed, 2015-01-14 at 11:29 +0100, Urs Liska wrote:
  Am 14.01.2015 um 11:18 schrieb Mattes:
 
  Am Mittwoch, 14. Januar 2015 09:42 CET, Urs Liska u...@openlilylib.org 
  schrieb:
 
  Yes, I made some surprising progress with Scheme recently. I didn't even
  get stuck in the ands and parens in the actual predicate I wrote
 
  #(define (annotation? obj)
(and
 (and (list? obj)
  (every pair? obj))
 (and (if (assoc-ref obj type) #t #f)
  (if (assoc-ref obj location) #t #f
  Proper indentation helps ;-)
  But why so contrived? Your code is equivalent to:
 
  #(define (annotation? obj)
   (and
(list? obj)
(every pair? obj)
(if (assoc-ref obj type) #t #f)
(if (assoc-ref obj location) #t #f)))
  ...  and is this just equivalent to:
 
  #(define (annotation? obj)
(and
 (list? obj)
 (every pair? obj)
 (assoc-ref obj type)
 (assoc-ref obj location)))
 
 
  ???
 
 I don't think so because the result of the function would be the result 
 of the last expression.

yes, and in Scheme all expressions except #f are true. (That's why #t is
used so rarely, because it is just an empty symbol, used when you
haven't got anything else.)

Richard



 assoc-ref returns the value to the key, so if passed a valid object 
 the result of the predicate wouldn't be #t but the content of location.
 That's why I enclosed these checks in if constructs.
 
 Urs
 
 
  Richard
 
 
 
  HTH Ralf Mattes
 
 
 
  Thanks, this is of course better.
  sorting out nested conditionals has never been my strongest point ;-)
 
  Urs
 
  ___
  lilypond-user mailing list
  lilypond-user@gnu.org
  https://lists.gnu.org/mailman/listinfo/lilypond-user
 
 



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


Re: Attaching an alist to a grob

2015-01-14 Thread Richard Shann
On Wed, 2015-01-14 at 11:29 +0100, Urs Liska wrote:
 Am 14.01.2015 um 11:18 schrieb Mattes:

  Am Mittwoch, 14. Januar 2015 09:42 CET, Urs Liska u...@openlilylib.org 
  schrieb:

  Yes, I made some surprising progress with Scheme recently. I didn't even
  get stuck in the ands and parens in the actual predicate I wrote
 
  #(define (annotation? obj)
   (and
(and (list? obj)
 (every pair? obj))
(and (if (assoc-ref obj type) #t #f)
 (if (assoc-ref obj location) #t #f
  Proper indentation helps ;-)
  But why so contrived? Your code is equivalent to:
 
  #(define (annotation? obj)
  (and
   (list? obj)
   (every pair? obj)
   (if (assoc-ref obj type) #t #f)
   (if (assoc-ref obj location) #t #f)))

...  and is this just equivalent to:

#(define (annotation? obj)
 (and
  (list? obj)
  (every pair? obj)
  (assoc-ref obj type)
  (assoc-ref obj location)))


???

Richard



 
  HTH Ralf Mattes


 
 
 Thanks, this is of course better.
 sorting out nested conditionals has never been my strongest point ;-)
 
 Urs
 
 ___
 lilypond-user mailing list
 lilypond-user@gnu.org
 https://lists.gnu.org/mailman/listinfo/lilypond-user



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


Re: Attaching an alist to a grob

2015-01-14 Thread Urs Liska


Am 14.01.2015 um 12:28 schrieb Richard Shann:

On Wed, 2015-01-14 at 11:29 +0100, Urs Liska wrote:

Am 14.01.2015 um 11:18 schrieb Mattes:
   
Am Mittwoch, 14. Januar 2015 09:42 CET, Urs Liska u...@openlilylib.org schrieb:
   

Yes, I made some surprising progress with Scheme recently. I didn't even
get stuck in the ands and parens in the actual predicate I wrote

#(define (annotation? obj)
  (and
   (and (list? obj)
(every pair? obj))
   (and (if (assoc-ref obj type) #t #f)
(if (assoc-ref obj location) #t #f

Proper indentation helps ;-)
But why so contrived? Your code is equivalent to:

#(define (annotation? obj)
 (and
  (list? obj)
  (every pair? obj)
  (if (assoc-ref obj type) #t #f)
  (if (assoc-ref obj location) #t #f)))

...  and is this just equivalent to:

#(define (annotation? obj)
  (and
   (list? obj)
   (every pair? obj)
   (assoc-ref obj type)
   (assoc-ref obj location)))


???


I don't think so because the result of the function would be the result 
of the last expression.
assoc-ref returns the value to the key, so if passed a valid object 
the result of the predicate wouldn't be #t but the content of location.

That's why I enclosed these checks in if constructs.

Urs



Richard




HTH Ralf Mattes
   
   


Thanks, this is of course better.
sorting out nested conditionals has never been my strongest point ;-)

Urs

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





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


Re: Attaching an alist to a grob

2015-01-14 Thread Mattes

Am Mittwoch, 14. Januar 2015 12:34 CET, Urs Liska u...@openlilylib.org 
schrieb:



  #(define (annotation? obj)
   (and
(list? obj)
(every pair? obj)
(if (assoc-ref obj type) #t #f)
(if (assoc-ref obj location) #t #f)))
  ...  and is this just equivalent to:
 
  #(define (annotation? obj)
(and
 (list? obj)
 (every pair? obj)
 (assoc-ref obj type)
 (assoc-ref obj location)))
 
 
  ???

 I don't think so because the result of the function would be the result
 of the last expression.
 assoc-ref returns the value to the key, so if passed a valid object
 the result of the predicate wouldn't be #t but the content of location.
 That's why I enclosed these checks in if constructs.

Richard is right, the if-clauses aren't neccessary. Scheme has the
concept generalized booleans, i.e. anything that isn't explicitly
false is considered to be true:

 guile (if 42 'true 'false)

I was just trying to keep as much of your code as possible 

 Cheers, RalfD



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


Re: Attaching an alist to a grob

2015-01-14 Thread Mattes
 
Am Mittwoch, 14. Januar 2015 13:56 CET, Urs Liska u...@openlilylib.org 
schrieb: 
 
 OK, I see.
 But somehow it feels wrong that
 
 #(display annotation? some-obj)
 
 doesn't produce #t but the content of location.
 Should I ignore that feeling?

If you intended to write

 #(display (annotation? some-obj))

then, yes, ignore that feeling. Scheme, like all Lisps (that I know of)  has 
generalized booleans,
so anything that's not explicitly false [1] is considered true. Because of this 
you hardly ever see
a litteral #t in Scheme code.

 Cheers, RalfD

[1] while Scheme considers #f to be the only _false_ value, Common Lisp et al. 
also consider
  the empty list '() as a valse value.


 Urs
 
 
 
 
 


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


Re: Attaching an alist to a grob

2015-01-14 Thread Urs Liska


Am 14.01.2015 um 12:42 schrieb Mattes:

Am Mittwoch, 14. Januar 2015 12:34 CET, Urs Liska u...@openlilylib.org 
schrieb:


#(define (annotation? obj)
  (and
   (list? obj)
   (every pair? obj)
   (if (assoc-ref obj type) #t #f)
   (if (assoc-ref obj location) #t #f)))

...  and is this just equivalent to:

#(define (annotation? obj)
   (and
(list? obj)
(every pair? obj)
(assoc-ref obj type)
(assoc-ref obj location)))


???

I don't think so because the result of the function would be the result
of the last expression.
assoc-ref returns the value to the key, so if passed a valid object
the result of the predicate wouldn't be #t but the content of location.
That's why I enclosed these checks in if constructs.

Richard is right, the if-clauses aren't neccessary. Scheme has the
concept generalized booleans, i.e. anything that isn't explicitly
false is considered to be true:

  guile (if 42 'true 'false)

I was just trying to keep as much of your code as possible 

  Cheers, RalfD



OK, I see.
But somehow it feels wrong that

#(display annotation? some-obj)

doesn't produce #t but the content of location.
Should I ignore that feeling?

Urs


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


Re: Attaching an alist to a grob

2015-01-13 Thread Paul Morris
Urs Liska wrote
 Now I've checked - it's perfect. Thank you again!
 
 There is no alist? predicate, but it's very easy to define:
 
 #(define (alist? lst)
 (and (list? lst)
(every pair? lst)))

Glad to help and glad someone else is benefiting from this.  (On a related
note, I also worked out how to create custom context properties if that's
ever useful.)

Hey, look at you slinging that Scheme like it was nothing!  ;-)

Cheers,
-Paul





--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Attaching-an-alist-to-a-grob-tp170412p170434.html
Sent from the User mailing list archive at Nabble.com.

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


Re: Attaching an alist to a grob

2015-01-13 Thread Paul Morris
Urs Liska wrote
 So does anyone have an idea how I can attach an alist to a grob so that 
 an engraver can retrieve it?
 Is it for example possible to add an arbitrary property to a grob?

Hi Urs,  I've had good luck creating custom grob properties, which sounds
like what you're looking for.  Here's how I do it, with some example custom
properties that I use:

%% CUSTOM GROB PROPERTIES
%% I use cn- to keep my functions separate from standard
%% LilyPond functions (like a poor man's namespace).

% function from scm/define-grob-properties.scm (modified)
#(define (cn-define-grob-property symbol type?)
   (set-object-property! symbol 'backend-type? type?)
   (set-object-property! symbol 'backend-doc custom grob property)
   symbol)

#(cn-define-grob-property 'cn-is-clairnote-staff boolean?)

#(cn-define-grob-property 'cn-vscale-staff number?)


Once they are defined I can use the custom properties with any grob (e.g.
StaffSymbol):

\override StaffSymbol.cn-is-clairnote-staff = ##t
\override StaffSymbol.cn-vscale-staff = #1.2


I suppose for an alist you would just use list? as the type predicate (or
maybe there's one for alists?).

Cheers,
-Paul



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Attaching-an-alist-to-a-grob-tp170412p170416.html
Sent from the User mailing list archive at Nabble.com.

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


Re: Attaching an alist to a grob

2015-01-13 Thread Paul Morris
Paul Morris wrote
 %% I use cn- to keep my functions separate from standard
 %% LilyPond functions (like a poor man's namespace).

Well, I should have said functions, custom property names, etc.
separate...

-Paul



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Attaching-an-alist-to-a-grob-tp170412p170417.html
Sent from the User mailing list archive at Nabble.com.

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


Re: Attaching an alist to a grob

2015-01-13 Thread Urs Liska
Hi Paul,

thanks for that. 
Will have to try that out later today, but indeed it looks exactly like what 
I'm looking for. 
I think I can soon give back the results :-)

Best
Urs

Am 13. Januar 2015 20:45:31 MEZ, schrieb Paul Morris p...@paulwmorris.com:
Urs Liska wrote
 So does anyone have an idea how I can attach an alist to a grob so
that 
 an engraver can retrieve it?
 Is it for example possible to add an arbitrary property to a grob?

Hi Urs,  I've had good luck creating custom grob properties, which
sounds
like what you're looking for.  Here's how I do it, with some example
custom
properties that I use:

%% CUSTOM GROB PROPERTIES
%% I use cn- to keep my functions separate from standard
%% LilyPond functions (like a poor man's namespace).

% function from scm/define-grob-properties.scm (modified)
#(define (cn-define-grob-property symbol type?)
   (set-object-property! symbol 'backend-type? type?)
   (set-object-property! symbol 'backend-doc custom grob property)
   symbol)

#(cn-define-grob-property 'cn-is-clairnote-staff boolean?)

#(cn-define-grob-property 'cn-vscale-staff number?)


Once they are defined I can use the custom properties with any grob
(e.g.
StaffSymbol):

\override StaffSymbol.cn-is-clairnote-staff = ##t
\override StaffSymbol.cn-vscale-staff = #1.2


I suppose for an alist you would just use list? as the type predicate
(or
maybe there's one for alists?).

Cheers,
-Paul



--
View this message in context:
http://lilypond.1069038.n5.nabble.com/Attaching-an-alist-to-a-grob-tp170412p170416.html
Sent from the User mailing list archive at Nabble.com.

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


Re: Attaching an alist to a grob

2015-01-13 Thread Urs Liska


Am 13.01.2015 um 21:41 schrieb Urs Liska:

Hi Paul,

thanks for that.
Will have to try that out later today, but indeed it looks exactly 
like what I'm looking for.

I think I can soon give back the results :-)


Now I've checked - it's perfect. Thank you again!

There is no alist? predicate, but it's very easy to define:

#(define (alist? lst)
   (and (list? lst)
  (every pair? lst)))

Best
Urs



Best
Urs

Am 13. Januar 2015 20:45:31 MEZ, schrieb Paul Morris 
p...@paulwmorris.com:


Urs Liska wrote

So does anyone have an idea how I can attach an alist to a
grob so that an engraver can retrieve it? Is it for example
possible to add an arbitrary property to a grob? 



Hi Urs,  I've had good luck creating custom grob properties, which sounds
like what you're looking for.  Here's how I do it, with some example custom
properties that I use:

%% CUSTOM GROB PROPERTIES
%% I use cn- to keep my functions separate from standard
%% LilyPond functions (like a poor man's namespace).

% function from scm/define-grob-properties.scm (modified)
#(define (cn-define-grob-property symbol type?)
(set-object-property! symbol 'backend-type? type?)
(set-object-property! symbol 'backend-doc custom grob property)
symbol)

#(cn-define-grob-property 'cn-is-clairnote-staff boolean?)

#(cn-define-grob-property 'cn-vscale-staff number?)


Once they are defined I can use the custom properties with any grob (e.g.
StaffSymbol):

\overrideStaffSymbol.cn  http://StaffSymbol.cn-is-clairnote-staff = ##t
\overrideStaffSymbol.cn  http://StaffSymbol.cn-vscale-staff = #1.2


I suppose for an alist you would just use list? as the type predicate (or
maybe there's one for alists?).

Cheers,
-Paul



--
View this message in 
context:http://lilypond.1069038.n5.nabble.com/Attaching-an-alist-to-a-grob-tp170412p170416.html
Sent from the User mailing list archive atNabble.com  http://Nabble.com.



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



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


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