Hi Edwin,

> >> having difficulty knowing when to use (prog) or (run).
> >> bottomline is, when is it best to use one over the other?
> >
> > 'run' is more general and evaluating version, i.e. it's a function
> ...
> i've run across 'evaluating' and 'non evaluating' versions of
> functions. not just in this list but also in reading materials. i
> haven't experienced the difference between the two yet.

Indeed. This is a central concept.

An evaluating function is generally more powerful, while a
non-evaluating one might be more convenient. You can always use the
evaluating version instead of the non-evaluating one (at the expense of
more writing), but not vice versa.

The most obvious case is 'set' vs. 'setq'. A call to the
(non-evaluating) 'setq'

   (setq A 123)

can be replaced with the evaluating (evaluating) 'set'

   (set 'A 123)

However, a call like

   (set (foo (bar)) 123)

cannot be replaced with 'setq', because the result of calling 'foo' must
be found out by evaluation first.

The same with the original question of using 'prog' or 'run'.

'run' is a function which evaluates its argument, and then runs it

   : (run (list '(println 1) '(println 2)))
   -> 2

After evaluation, 'run' sees the list ((println 1) (println 2)), and
executes it.

So instead of 'prog', you could always use 'run' with a quoted argument
list (analog to the 'set' / 'setq' example above):

   : (prog (println 1) (println 2))
   -> 2

   : (run '((println 1) (println 2)))
   -> 2

That's the whole difference.

- Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to