For Programmers: Free Programming Magazines  


Home > Archive > Functional > May 2007 > Re: Empty function composition (was: Re: How Lisp's Nested Notation









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Empty function composition (was: Re: How Lisp's Nested Notation
Ville Oikarinen

2007-05-22, 8:04 am

On Mon, 21 May 2007, Simon Richard Clarkstone wrote:

> Ville Oikarinen wrote:
>
> There is a potential bug in your acceptance tests. Normally in
> programming and mathematics, an empty composition is not an error but is
> the identity function, as the identity function is also the left and
> right identity element for function composition. Is there a special
> reason that this case is different?


It's because $:compose is not really a mathematical composition function
that gets a list of functions and returns a composition function.

Instead it uses its first child as the variable declaration that both
defines the initial value and the symbol that can be used to refer the
current var value in the "function" expressions. So it kind of creates the
composition and calls it at the same time.

In ngrease an empty composition is a $:compose expression that has no
other children than the initial value declaration (see the second
acceptance test for an example).

I admit that the expression should probably have some other name than
compose, because it does two things. What would be a good name?
compose-call?

Maybe a function-generating variation of the $:compose expression could
work like this (just an unimplemented sketch that may have typos):

$:assert:$:equals {
abc
$:with {
f:$:quote:$:compose {
_
$:append-symbols {$:_ b}
$:append-symbols {$:_ c}
}
$:f:a
}
}

Here the first child of $:compose just defines the symbol without an
initial value. In this example f will be an expression that, when
evaluated, reads the only child, a, from its invocation and binds it to _
before evaluating the subexpressions in sequence.

- Ville Oikarinen
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com