FWIW, running the same code in a Dyalog APL Jupyter notebook gives similar 
results :

Quid des fonctions et lambdas dyadiques ?


```APL
⍝ 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
```

<pre class="language-APL">clear ws
</pre>


```APL
∇ R ← NTS
  R ← 24 60 60 1000 ⊥ ¯4↑⎕TS
∇
```

```APL
⍝ Try it
T1 ← NTS
⍝ Wait a few seconds
⍝ )host sleep 2
⎕DL 2
T2 ← NTS
⍞←'Spent Time : ',⍕(T2-T1)÷1000
```

<pre class="language-APL">Spent Time : 2.51
</pre>

```APL
⍝ 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
```

<pre class="language-APL">Spent time : 0
</pre>


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



Reply via email to