Re: [stack] sweetening concatenative syntax

Manfred Von Thun <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <C40730AF.F99%[email protected]>


On 19/3/08 6:06 PM, "John Nowak" <[email protected]> wrote:

> 
> On Mar 18, 2008, at 10:17 PM, Manfred Von Thun wrote:
> 
>> quad turns [C:num, B:num, A:num | R] into [[P:num,N:num] list | R] :-
>> Diff is B*B -$*A*C,
>> (   Diff < 0.0,
>> ->  write(Œquadratic: cannot take root of negative argument¹)
>> ;   Root is sqrt(Diff),
>>    P is (0-B+Root)/(2*A),
>>    N is (0-B-Root)/(2*A)
>> ).
> 
> Here's another version of the above with a syntax more suited to a
> concatenative language:
> 
> quad a b c = p n
>     where d = b 4 a c * * -
>           r = d 0 >= [d sqrt] ["quad: sqrt of negative" error] if
>           x = 2 a *
>           p = b r - x /
>           n = b r + x /
> 

Yes, I entirely agree. What I gave was the Prolog program, and if
someone implementing a concatenative language has to choose
a notation for arithmetic and other types, our form would be best.
But to get the unification for the variables in the input and the
output stacks, you have to write a little Prolog ­ and that is not so easy.
So I just used an excellent existing Prolog, SWI-prolog.




[Non-text portions of this message have been removed]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.