What, precisely, is the use of "always()"? 
Author Message
 What, precisely, is the use of "always()"?

I have difficulty finding any use whatsoever for the always() function.
Could somebody please enlighten me?  What can always() do that merely using
its argument by itself couldn't do for you?


Fri, 16 Nov 2001 03:00:00 GMT  
 What, precisely, is the use of "always()"?


Quote:
>I have difficulty finding any use whatsoever for the always() function.
>Could somebody please enlighten me?  What can always() do that merely
using
>its argument by itself couldn't do for you?

The last time I used it was when defining a condition handler:

begin
        let handler <my-cond> = always(#f);

        // some code that signals a <my-cond>
        local process(it :: <integer>)
                        let handler <my-cond> = always(it);
                        // some code that signals a <my-cond>
                        end;

        map(process, some-integer-sequence)
end

it worked as advertised for me.

        Gabor



Fri, 16 Nov 2001 03:00:00 GMT  
 What, precisely, is the use of "always()"?



Quote:
> I have difficulty finding any use whatsoever for the always() function.
> Could somebody please enlighten me?  What can always() do that merely using
> its argument by itself couldn't do for you?

See the Reference Manual, near the end of Chapter 12, Builtin Functions.
The always() function returns a function that can be called with any number
of arguments, but always returns the same object.

--Ivan Frohne



Fri, 16 Nov 2001 03:00:00 GMT  
 What, precisely, is the use of "always()"?

Quote:



> > I have difficulty finding any use whatsoever for the always() function.
> > Could somebody please enlighten me?  What can always() do that merely using
> > its argument by itself couldn't do for you?

> See the Reference Manual, near the end of Chapter 12, Builtin Functions.
> The always() function returns a function that can be called with any number
> of arguments, but always returns the same object.

always(thing)

is just shorthand for

method (#rest x)
  thing
end

It hardly seems necessary to have it in the language, especially
given how rarely it seems to be used.  Here's one possible use:

define method maybe-do
    (f :: <function>, s :: <sequence>, #key test = always(#t))
 => ()
  do(method (item)
       test(item) & f(item)
     end,
     s)
end method maybe-do;

So by default maybe-do is similar to do, but it allows you to
pass a test function to only do certain items.
There must be a more compelling use for the beasty...

-Carl



Sat, 17 Nov 2001 03:00:00 GMT  
 What, precisely, is the use of "always()"?

Quote:

> always(thing)

> is just shorthand for

> method (#rest x)
>   thing
> end

> It hardly seems necessary to have it in the language, especially
> given how rarely it seems to be used.

That's true at one level -- looking at Dylan as a traditional procedural
language -- but I think it fits in when viewing Dylan as a functional
language.

You could also look at it from a purely efficiency basis.  If you do
happen to be using "always(thing)" all over the place, and you used
"method() thing end" instead, then you'll be getting large numbers of
little functions, essentially identical to each other, all over the place
in your object code.

always(thing) is better defined as:

  curry(identity, thing)

... when identity is...

  method (x, #rest y)
      x
  end

Of course, "identity" is also built in to the language, and is probably
exactly as useless as "always" :-)

The big difference here is that he implementation of "curry" doesn't
produce code, but just produces a little data structure at runtime,
containing a pointer to the "identity" function, and a pointer to "thing"
(plus maybe a small thunk or else a pointer to the call-time code for
curry).  This data structure might even end up being allocated on the
stack, but at any rate it's likely to use less memory (especially on a
permanent basis) than an anonymous method.

Built in functions for "curry", "identity" and "always" may also be able
to be optomised better, as the compiler can have magic for them.

-- Bruce



Sat, 17 Nov 2001 03:00:00 GMT  
 What, precisely, is the use of "always()"?

Quote:



> > always(thing)

> > is just shorthand for

> > method (#rest x)
> >   thing
> > end

> > It hardly seems necessary to have it in the language, especially
> > given how rarely it seems to be used.

> That's true at one level -- looking at Dylan as a traditional procedural
> language -- but I think it fits in when viewing Dylan as a functional
> language.

This is especially true if you consider "always" as related to the K
combinator in combinatory logic (CL).  K is defined by the following
equation:

        KPQ = P, for any terms P and Q.

If you also define the S combinator as

        SPQR = PR(QR), for any terms P, Q, and R

then there are standard translations from CL to the (untyped) lambda
calculus and back.  CL and the lambda calculus provide the theoretical
foundations for functional programming languages (or, IMO, all
programming languages).

- Show quoted text -

Quote:
> You could also look at it from a purely efficiency basis.  If you do
> happen to be using "always(thing)" all over the place, and you used
> "method() thing end" instead, then you'll be getting large numbers of
> little functions, essentially identical to each other, all over the place
> in your object code.

> always(thing) is better defined as:

>   curry(identity, thing)

> ... when identity is...

>   method (x, #rest y)
>       x
>   end

> Of course, "identity" is also built in to the language, and is probably
> exactly as useless as "always" :-)

I find "identity" useful as the default "do nothing" function argument
to map-as and map-into, among other things.

Feeling [theoret|histor]ical this mornin'.
--

Sullivan  http://www.ai.mit.edu/~gregs/



Sat, 17 Nov 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Always get "Changes will be lost..."

2. dialog box always says "save"

3. "always on top" control panel

4. maximum number of "always" statement

5. starkit::startup always return "sourced"

6. sending "no" always to a process

7. winfo width returns always "1"

8. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

9. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

10. Parsing ""D""?

11. "Fifth", "Forth", zai nar?

 

 
Powered by phpBB® Forum Software