Re: [RFC PATCH 02/28] cli: Add LIL shell

Sean Anderson
2021-07-07T13:32:30Z

On 7/6/21 12:09 PM, Kostas Michalopoulos wrote:
> On 7/6/2021 6:43 PM, Tom Rini wrote:
>> I don't know if it's right either. But drawing on my comment just now
>> and above about complex boot scripts, I also don't know if "it's sh but
>> quirky and incomplete, WHY DOESN'T THIS WORK RIGHT" is better than "It's
>> TCL? I don't know that, let me hit stackoverflow and do a little
>> reading" as would be the common experience. Especially if we document
>> up-front what the quirks we have are.
>
> I think the same would happen with Tcl and LIL. LIL might look similar
> to Tcl (and it is inspired by it), but it doesn't have the same
> syntax. A big difference comes from how variables are parsed with LIL
> allowing more variables symbols than Tcl without requiring escaping
> which affects some uses like expr, so e.g. in Tcl this
>
> set a 10 ; set b 20 ; expr $a+$b
>
> will give back 30 however in LIL will give back 20. This is because
> Tcl parses "$a+$b" as "$a" "+" "$b" whereas LIL parses it as "$a+"
> "$b", evaluates "$a+" as an empty string (there isn't any "a+"
> variable), "$b" as 20 and then just runs expr with the single argument
> "20".

IMO both of these are nuts. I think the best thing to do here is
to raise an error about a missing variable "a+" to force the user to
rewrite this as

set a 10 ; set b 20 ; expr ${a}+$b

removing the ambiguity. Although I would generally like to follow TCL's
lead, there are several places where TCL does crazy things (e.g.
comments) which I have purposely not replicated.

--Sean