Sujet : Re: Integral types and own type definitions (was Re: Suggested method for returning a string from a C program?)
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 31. Mar 2025, 20:48:36
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250331124001.899@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-03-31, Alan Mackenzie <
acm@muc.de> wrote:
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>
[ .... ]
>
I don't know of any language that uses "-" for both negation (prefix,
one operand) and subtraction (infix, two operands) and treats -5
as a single token rather than a unary minus operator applied to the
constant/literal "5".
>
How about Lisp? The unary operator is (- 5), the binary (- 10 5).
>
It doesn't match your second parenthetical remark ("infix") but
otherwise it does.
Lisp could be infix if we want with some macro:
(infix-environment
... (10 - (a * 3)) ...)
Here, the fictional macro infix-environment implements a code walker of
its interior looking for situations where the second place of a form is
a symbol with a function binding, and the first place isn't a symbol, or
not one with a function binding. Those expressions are then treated by
a conversion of (x1 x2 x3 ...) to (infix x1 x2 x3). When the conversion
is complete, the infix-environment macro removes itself, or rewrites
itself to progn. The (also fictitious) infix macro then expands the
infixes, turning (infix 10 - (a * 3)) into (- 10 (* a 3)).
Things like (a cons (b cons c)) would also work for (cons a (cons b c)),
not only math infix. However, the infix macro could recognize
infix without parentheses, using operator precedence.
So then we would have a language in which we have - A unary,
A - B infix, and -5 is a negative constant.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca