powershell, perl, syntax soup

On Aug 8, 2:04 pm, Robert Uhl wrote:
> Bill McCleary writes:
> > Sure there is. Its syntax. There are psyops agents in the CIA that would
> > *kill* to know how Larry Wall devised such a deviously devilish mindjob!
> There's a good reason for Perl's arcane syntax: it is derived from shell
> syntax. In shells, symbols are the default and variables are the
> special case, so symbols are unquoted but variables must be indicated
> with a dollar sign. This convention was inherited by awk, where it made
> less sense, and thence by perl, where it made even less sense. However,
> it did provide an opportunity to indicate different types of variables
> with different sigils, with '$' used to indicate strings & numbers, as
> in shells, and @, %, & and * used for other types.
> Then there are all the implicit argument rules and such which _can_
> often do what the programmer means...and can just as often not.
> Then there are references and classes, which are a neat hack.
> Perl is a language whose design decisions made since at every step of
> the way, but whose final overall design is, frankly, ugly. I understand
> how it got where it is, and back when the choice was shell or perl, the
> answer was easy: perl. But nowadays there are better scripting
> languages like Python. Also, better dynamic languages like Common Lisp
> are freely available. So I don't see much reason to use Perl anymore.

recently i started to learn PowerShell, which is a scripting lang but also a shell. First of all, PowerShell was a fantastic shell lang, based on modern design, in the early 2000s, as opposed to unix's 1980. It was known as Monad, and has a lot features. It was based entirely on .NET, and support all unix shell's advantages and concepts.

though, i was rather surprised, that its syntax has a lot similarities with perl or unix shell. Piping “|”, dollar sign “$” for vars, redirect “>”, append “>>”, logic operator “&”, predefined var such as “$_”, “$?”, heredoc, array “@(1,2,3)”, array access “$x[3]”, “$aa[2][1]”, hash “@{'a'=1; 'x'='5'; 6=4; '6'=7}”, boolean operator “-eq”, “-ne”, “gt”, string expansion (aka “interpolation”) “"x is $x"” ...

so, that was a surprise for me. The key to note is that PowerShell is a cleanly designed from the ground up of a shell language, however, one gets the sense that perhaps a shell language which requires brevity must have syntax soup syndrome. The above examples barely illustrate PowerShell's brevity, because it has a lot more advance syntax sugars that i have yet to understand.

i haven't studied this issue in depth, but in my opinion, one could have a brief syntax yet based on a consistent syntax system, as opposed to ad hoc syntax soup. Mathematica is a example. For a exposition on this, see:

• The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations

Here's my PowerShell tutorial. Right now pretty basic:

• Xah's PowerShell Tutorial

> Incidentally, I recently converted some tasks to Common Lisp from
> Python. Wow...the speedup was _amazing_. And this was simple stuff:
> scan in a CSV file then apply a function to every item. While it wasn't
> _slow_ in Python, it blazed in CL. Dunno how well Perl would have done;
> somewhere in between I guess.

Try Ocaml, it'd blow python or perl or Common Lisp to pieces.

unscrupulous self promotion:

• Xah's OCaml Tutorial

∑ http://xahlee.org/

No comments:

Post a Comment