On Sun, Jan 05, 2025 at 02:23:15AM -0800, Kurt Pagani wrote:
<fixed order>
> > On Saturday, 4 January 2025 at 19:08:08 UTC+1 Sid Andal wrote:
> >
> >> The file test.input contains the following lines from the manual
> >> on acceptable (indented) if-then-else expressions:
> >>
> >> cat test.input:
> >>
> >> if 1 > 0 then output("positive") else output("nonpositive")
> >>
> >> if 1 > 0 then output("positive")
> >>    else output("nonpositive")
<snip>
> >> Except for the first one-liner, the remaining ones give syntax errors:

The ones above work for me.

> You are right, this does not hold anymore (apparently). The docs should be 
> adjusted? I wasn't aware of this exception of the pile rule.
> 
> --- chapter 5.3
> *The usual rules for piles are suspended for conditional expressions. In 
> .input files,* the then and else keywords can begin in the same column as 
> the corresponding if but may also appear to the right. Each of the 
> following styles of writing if-then-else expressions is acceptable:

This if very loose formulation, actual rules are much more complicated
(and currently it is hard to explain them better than "follow the
source code of pile handling").  It could be true of handling in the
"old compiler", but this is no longer in use.

One thing is that handling at indentation level 0 (that is for top
level constructs) is different.  So let me assume that we are inside
a function.

> if i>0 then output("positive") else output("nonpositive")
> 
> if i > 0 then output("positive")
>   else output("nonpositive")

This is misleading because

foo2(i) ==
  if i > 0 then 
    output("positive")
    else output("nonpositive")

does not work.  That is example number 2 works because of rule
"single line makes no pile", not because of handling for 'if'
(and for me it also works at top level).

> if i > 0 then output("positive")
> else output("nonpositive")
> 
> if i > 0
> then output("positive")
> else output("nonpositive")
>
> if i > 0
>   then output("positive")
>   else output("nonpositive")
> ---
> 
> In function bodies it's ok.
> 
> f(x) ==
>   if x > 0 then
>     return 1
>   else
>     return 0

Actually, for me

foo5(i) ==
  if i > 0
    then output("positive")
    else output("nonpositive")

fails.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/Z3qDt03gC1vfhc0h%40fricas.org.

Reply via email to