Hi Ala,
the thing is simply that in GNU APL (I don't know how other APLs
do it)
time ←
{⎕TS}
⎕CR 'time' ⍝ time is a variable
⍴⎕CR 'time'
0 0
does NOT create a named lambda with the name time
but it creates
an unnamed niladic lambda which is immediately evaluated and
result
is assigned to variable time.
In contrast, for example
time←{⎕TS ⍵}
⎕CR 'time' ⍝ time is a monadic
function
λ←λ1 ⍵
λ←⎕TS ⍵
does first creates an
unnamed monadic lambda λ1, which can (unlike
in the niladic case) NOT be immediately evaluated and is instead
shifted until time←λ1 can be evaluated,
As a consequence,
time ← {⎕TS}
and
time ← {⎕TS ⍵}
look very similar but they do very different things. Another
consequence is
that in GNU APL you cannot create a named niladic lambda.
In your example 1 you do not want to
time ← {⎕TS}
but this:
⎕FX 'Z→time'
'Z←⎕TS'
/// Jürgen
On 10/26/2016 04:15 PM, Ala'a Mohammad
wrote:
Hi,
I previously had similar cases, but could not understand them. since
they are worknig for functions, but not lambdas, and assumed that is
the case.
Now, after reading "This is normal APL and holds for all niladic
functions and not only for niladic lambdas.", I'm more confused. if
I'm not missing anything, the following is created with intent of side
effects or only returning results, rather than supplying argument and
getting results.
⍝ Example 1 (providing alternate name for ⎕TS)
time ← {⎕TS}
time
2016 10 26 18 1 36 586
time
2016 10 26 18 1 36 586
∇T←timeit
T←⎕TS
∇
timeit
2016 10 26 18 8 59 823
timeit
2016 10 26 18 9 2 471
⍝ Example 2 (throw 2 dices 10 times)
rand ←{?10 2⍴6}
rand≡rand
1
∇R←rand1
R←?10 2⍴6
∇
rand1≡rand1
0
What is that I'm missing and do not understand between the quoted text
above and the results above?
Regards,
Ala'a
On Wed, Oct 26, 2016 at 2:54 PM, Juergen Sauermann
<[email protected]> wrote:
Hi,
correct. To explain why this is so, consider this:
{1+2}
3
{1+⍵}
SYNTAX ERROR
{1+⍵} 5
6
Therefore in
F0←{1+2}
GNU APL first reduces {1+2} to 3 and then assigns 3 to F0, making F0 a
variable
because a values is being assigned to a name. This is normal APL and holds
for
all niladic functions and not only for niladic lambdas.
In contrast, in
F1←{1+⍵}
{1+⍵} cannot be reduced (as opposed to {1+⍵} 5 which can), so it is shifted
onto
the evaluation stack, then ← is shifted (still not being able to be
reduced), and finally
F1 is shifted. At this point the stack contains the valid phrase F1←{1+⍵},
which can
be reduced and causes F1 to become a monadic function bound to the name F1.
/// Jürgen
On 10/25/2016 07:01 PM, Christian Robert wrote:
DISPLAYhand←{,(⍪hand),' '}
this create a variable DISPLAYhand
this is because de {} does not contain neither alpha nor omega.
Xtian.
On 2016-10-25 12:54, [email protected] wrote:
Hi bug-apl,
Why does DISPLAYhand not use the new value of hand on the second call?
deck←''
deck←deck,"🂢" "🂲" "🃂" "🃒"
deck←deck,"🂣" "🂳" "🃃" "🃓"
deck←deck,"🂤" "🂴" "🃄" "🃔"
deck←deck,"🂥" "🂵" "🃅" "🃕"
deck←deck,"🂦" "🂶" "🃆" "🃖"
deck←deck,"🂧" "🂷" "🃇" "🃗"
deck←deck,"🂨" "🂸" "🃈" "🃘"
deck←deck,"🂩" "🂹" "🃉" "🃙"
deck←deck,"🂪" "🂺" "🃊" "🃚"
deck←deck,"🂫" "🂻" "🃋" "🃛"
⍝deck←deck,"🂬" "🂼" "🃌" "🃜" ⍝knights
deck←deck,"🂭" "🂽" "🃍" "🃝"
deck←deck,"🂮" "🂾" "🃎" "🃞"
deck←deck,"🂡" "🂱" "🃁" "🃑"
deck ← ⊖13 4 ⍴ deck
hand←(∈deck)[13?52]
DISPLAYhand←{,(⍪hand),' '}
DISPLAYhand
🂢 🃈 🃃 🂷 🃞 🃙 🃝 🂫 🃋 🃕 🃒 🃂 🂧
hand←(∈deck)[13?52]
DISPLAYhand
🂢 🃈 🃃 🂷 🃞 🃙 🃝 🂫 🃋 🃕 🃒 🃂 🂧
hand
🂤🂺🂾🂷🂪🂱🂳🂸🃚🃅🂻🂲🂭
Thanks,
Alex
|