Re: [stack] function/object ambiguity + quotation alternative

John Nowak <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
On Mar 3, 2009, at 7:13 PM, Stevan Apter wrote:

> i don't know if it is necessary for typing.  i've heard lots of claims
> over the years that this and that are impossible in k, and of course  
> that's
> true ... until someone actually does this and that.  can k be typed?
> if not, how close can you get to k with a typed language?  is that  
> close
> enough?

I realize those are rhetorical questions, but...

The language prototype I'm working on now does take some vague  
inspiration from Q. For example, you can define a 'map' function named  
(') as such:

   ' = -x(n,x.{F,'F})

In the above definition, '-x' is a combining form that takes two  
functions. The first says what to do if the list passed to it is null  
(return null), and the second says what to do if passed a cons (apply  
some function F to the head, apply 'F to the tail, then cons the  
result).

You can use the map function as such:

   'sq.[1,2,3,4,5]   # [1,4,9,16,15]

Another example would be fold:

   / = +x(i,/F.[c,F.t2])

Here, '+x' is like '-x' except it takes additional values that are  
passed to both functions. The first argument to '+x' returns the  
additional values ('i' is identity) and the second folds some function  
F over tail of the list and F applied to the accumulated value and  
head of the list.

An example:

   /+.[[1,2,3,4,5],0]   # 15

Alright, it's not that much like Q. For one, it works on cons cells  
instead of arrays. It does have a nice advantage though: It's  
statically typed.

Just a little brain dump...

- John
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.