Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Purpose of apply

12 views
Skip to first unread message

ultranewb

unread,
Feb 13, 2011, 1:42:38 AM2/13/11
to
Hi, I'm new to tcl, so cut me some slack for asking a dumb question.

At any rate, I know what apply is and what apply does (or... I know
what the purpose of apply is in other languages, i.e. languages that
aren't like tcl). It just seems to me that you can get the same
effect in tcl without using apply.

(System32) 55 % apply {x {puts $x}} hi
hi
(System32) 56 % set x puts; $x hi
hi

I always thought languages with apply want the ability to do #2 above,
but of course can't do #2 above. So they have apply which allows this
effect. Tcl can do #2 above, so why need apply? My guess is, apply
is used for other things, or I have a general misnotion of what apply
is.

Thanks.

Alexandre Ferrieux

unread,
Feb 13, 2011, 4:38:28 AM2/13/11
to

The key difference between [apply] and variable-first-word is that
[apply] prepares a cosy space named a "call frame", that is a scope
for local variables, including the formal arguments of the lambda,
without any risk of collision with like-names vars of the calling
context; also, [return] within the body works the way you'd think it
does, unlike a [return] in an [eval] of similar intent.

In essence, [apply] creates an unnamed, one-shot proc; this, by the
way, is made rather clear in the apply.n manpage.

-Alex

0 new messages