|
From: | Emmanuel Charpentier |
Subject: | Re: Niladic functions vs niladic lambdas |
Date: | Thu, 08 Jun 2023 18:10:20 +0200 |
User-agent: | Evolution 3.46.4-2 |
FWIW, running the same code in a Dyalog APL Jupyter notebook gives similar results :
Quid des fonctions et lambdas dyadiques ?
⍝ What about niladic functions and lambdas ?
⍝ Example of a numeric timestamp generator
⍝ Simplifying assumptions : we want to measure about a few minutes
⍝ and not around midnight...
⍝ Start afresh
)clear
clear ws
∇ R ← NTS
R ← 24 60 60 1000 ⊥ ¯4↑⎕TS
∇
⍝ Try it
T1 ← NTS
⍝ Wait a few seconds
⍝ )host sleep 2
⎕DL 2
T2 ← NTS
⍞←'Spent Time : ',⍕(T2-T1)÷1000
Spent Time : 2.51
⍝ Lambda
nts ← {24 60 60 1000 ⊥ ¯4↑⎕TS}
⍝ Try it
t1 ← nts
⍝ Wait a few seconds
⍝ )host sleep 2
⎕DL 2
t2 ← nts
⍞←'Spent time : ',⍕(t2-t1)÷1000
Spent time : 0
Le jeudi 08 juin 2023 à 17:37 +0200, Emmanuel Charpentier a écrit :
Dear list, It seems that niladic lambdas are treated like constants. Rough and naïve illustration : pasting this :
⍝ What about niladic functions and lambdas ?
⍝ Example of a numeric timestamp generator ⍝ Simplifying assumptions : we want to measure about a few minutes ⍝ and not around midnight... ⍝ Start afresh )clear ⍝ Function ∇ R ← NTS R ← 24 60 60 1000 ⊥ ¯4↑⎕TS ∇ ⍝ Try it T1 ← NTS ⍝ Wait a few seconds )host sleep 2 T2 ← NTS ⍞←'Spent Time : ',⍕(T2-T1)÷1000 ⍝ Lambda nts ← {24 60 60 1000 ⊥ ¯4↑⎕TS} ⍝ Try it t1 ← nts ⍝ Wait a few seconds )host sleep 2 t2 ← nts ⍞←'Spent time : ',⍕(t2-t1)÷1000
in a `gnu-apl` buffer gives :
> ```
CLEAR WS
>
> 0
> Spent Time : 2.002
> 0
> Spent time : 0
Why ?
Bonus question : what causes the impression of the
0
s ? Sincerely, -- Emmanuel Charpentier
[Prev in Thread] | Current Thread | [Next in Thread] |