andrew cooke | 5 Apr 2004 22:50
Favicon
Gravatar

[stack] Pattern matching, stack comments


Hi,

Are either of these ideas useful?  I've not used Joy (or APL, J, K etc),
although I did play with Forth a little just under 20 years ago...

First - maybe you add some kind of support for comments on the stack, so
that operations that pushed values could attach comments.  Then a stack
dump might show not just values, but also comments.

Second - could you add pattern matching to definitions, to make them
simpler to read?  Then swap might be defined something like:
swap a b == b a

I can already see at least two objections to the second point - first that
it's not clear whether you match atomic values or sub-stacks and second
that you might lose much of the concatenative flavour of the language (or,
alternative, that if you're used to programming in a such a style, such
matching appears redundant).

Thanks,
Andrew

--

-- 
` __ _ __ ___  ___| |_____   work web site: http://www.ctio.noao.edu/~andrew
 / _` / _/ _ \/ _ \ / / -_)  personal web site: http://www.acooke.org/andrew
 \__,_\__\___/\___/_\_\___|  personal gallery: http://www.acooke.org/pancito

 
Yahoo! Groups Links
(Continue reading)

Tanksley, William D. Jr. | 6 Apr 2004 17:25
Picon
Favicon

RE: [stack] Pattern matching, stack comments

From: andrew cooke [mailto:andrew <at> acooke.org] 
>First - maybe you add some kind of support for comments on the 
>stack, so that operations that pushed values could attach 
>comments.  Then a stack dump might show not just values, but 
>also comments.

So you want annotations on arbitrary data (not on the stack, but on the
data)? That's not a bad idea, but you'd need to define a new datatype with
room for the annotation.

>Second - could you add pattern matching to definitions, to 
>make them simpler to read?  Then swap might be defined 
>something like: swap a b == b a

cK added this at my suggestion. I implemented it about 10 years ago in Pygmy
Forth as a machine-code generating compiler, and wanted to add support for
it to the parser (so that any word of the form abc--cba would generate
inline code for the pictured stack shuffle). cK handles it differently, by
providing a word that takes the stack picture as a string at runtime rather
than taking the picture as a token at compile-time, but either way the
effect is much the same (and a good compiler would theoretically generate
much the same code).

>I can already see at least two objections to the second point 
>- first that it's not clear whether you match atomic values or 
>sub-stacks

Substacks are values, so no problem. If you want to support pattern matching
within lists or other data structures, you have to define a syntax for it,
as Apter did for cK.
(Continue reading)

Don Groves | 6 Apr 2004 19:26

Re: [stack] Pattern matching, stack comments

On Tue, 6 Apr 2004 08:25:41 -0700, Tanksley, William D. Jr. <TanksleyJrW <at> saic.com> wrote:

> From: andrew cooke [mailto:andrew <at> acooke.org]
>> First - maybe you add some kind of support for comments on the
>> stack, so that operations that pushed values could attach
>> comments.  Then a stack dump might show not just values, but
>> also comments.
>
> So you want annotations on arbitrary data (not on the stack, but on the
> data)? That's not a bad idea, but you'd need to define a new datatype with
> room for the annotation.
>
>> Second - could you add pattern matching to definitions, to
>> make them simpler to read?  Then swap might be defined
>> something like: swap a b == b a
>
> cK added this at my suggestion. I implemented it about 10 years ago in Pygmy
> Forth as a machine-code generating compiler, and wanted to add support for
> it to the parser (so that any word of the form abc--cba would generate
> inline code for the pictured stack shuffle). ...snip...

The "abc" part is redundant here.  Something like "stack--cba"
would be self-documenting and more easily understood than "swap
rot", imho.  Or, "[3 2 1] shuffle", which can be extended to any
depth.

> I don't think it is -- it's certainly possible to express all possible stack
> manipulations with only a minimal set of stack operators, but it's not at
> all efficient or readable. Stack pictures DO help, in my long-past
> experience with my Forth mod.
(Continue reading)

Stevan Apter | 6 Apr 2004 22:13

Re: [stack] Pattern matching, stack comments


----- Original Message ----- 
From: "Don Groves" <dgroves <at> ccwebster.net>
To: <concatenative <at> yahoogroups.com>
Sent: Tuesday, April 06, 2004 1:26 PM
Subject: Re: [stack] Pattern matching, stack comments

> On Tue, 6 Apr 2004 08:25:41 -0700, Tanksley, William D. Jr. <TanksleyJrW <at> saic.com> wrote:
> 
> > From: andrew cooke [mailto:andrew <at> acooke.org]
> >> First - maybe you add some kind of support for comments on the
> >> stack, so that operations that pushed values could attach
> >> comments.  Then a stack dump might show not just values, but
> >> also comments.
> >
> > So you want annotations on arbitrary data (not on the stack, but on the
> > data)? That's not a bad idea, but you'd need to define a new datatype with
> > room for the annotation.
> >
> >> Second - could you add pattern matching to definitions, to
> >> make them simpler to read?  Then swap might be defined
> >> something like: swap a b == b a
> >
> > cK added this at my suggestion. I implemented it about 10 years ago in Pygmy
> > Forth as a machine-code generating compiler, and wanted to add support for
> > it to the parser (so that any word of the form abc--cba would generate
> > inline code for the pictured stack shuffle). ...snip...
> 
> The "abc" part is redundant here.  Something like "stack--cba"
> would be self-documenting and more easily understood than "swap
(Continue reading)

Rod Price | 6 Apr 2004 22:26
Picon
Favicon

[stack] newbie question

I've been reading this list for some time but have never
participated.  Now I want to ask a potentially embarrassing
newbie question:  Is there a free or inexpensive version
of K that I can get my hands on?  I'd like to experiment
with cK, and it seems that a copy of K is a prerequisite.

-Rod

On Apr 6, 2004, at 2:13 PM, Stevan Apter wrote:

>
> ----- Original Message -----
> From: "Don Groves" <dgroves <at> ccwebster.net>
> To: <concatenative <at> yahoogroups.com>
> Sent: Tuesday, April 06, 2004 1:26 PM
> Subject: Re: [stack] Pattern matching, stack comments
>
>
>> On Tue, 6 Apr 2004 08:25:41 -0700, Tanksley, William D. Jr.  
>> <TanksleyJrW <at> saic.com> wrote:
>>
>>> From: andrew cooke [mailto:andrew <at> acooke.org]
>>>> First - maybe you add some kind of support for comments on the
>>>> stack, so that operations that pushed values could attach
>>>> comments.  Then a stack dump might show not just values, but
>>>> also comments.
>>>
>>> So you want annotations on arbitrary data (not on the stack, but on  
>>> the
>>> data)? That's not a bad idea, but you'd need to define a new  
(Continue reading)

Tanksley, William D. Jr. | 6 Apr 2004 22:50
Picon
Favicon

RE: [stack] Pattern matching, stack comments

From: Don Groves [mailto:dgroves <at> ccwebster.net] 
>The "abc" part is redundant here.  Something like "stack--cba" 
>would be self-documenting and more easily understood than 
>"swap rot", imho.  Or, "[3 2 1] shuffle", which can be 
>extended to any depth.

OTOH, being able to use terms like "xyz--xyzzy" versus "abc--cbcba" does
allow you to maintain a visible difference between different items. In that
case the two shuffles might be handling completely different items --
perhaps there's a "abcxyz--xyzabc" somewhere between them.

In addition, as Stevan pointed out, you can also express other patterns,
such as lists. "ab[cd]--ac[bd]" is a possible example. I like the idea, but
I can't imagine using it :-). If I did, I'd probably modify it to
pattern-match against the car and cdr of the list, not against every
specific item in the list. That way every list pattern would work for ANY
list, not just the lists with the same length as the pattern.

>dg

-Billy

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/concatenative/

<*> To unsubscribe from this group, send an email to:
     concatenative-unsubscribe <at> yahoogroups.com
(Continue reading)

Tanksley, William D. Jr. | 6 Apr 2004 23:02
Picon
Favicon

RE: [stack] newbie question

From: Rod Price [mailto:rod.price <at> ngc.com] 
>I've been reading this list for some time but have never 
>participated.  Now I want to ask a potentially embarrassing 
>newbie question:  Is there a free or inexpensive version of K 
>that I can get my hands on?  I'd like to experiment with cK, 
>and it seems that a copy of K is a prerequisite.

K is only available from www.kx.com, and you'll want to get the evaluation
version (really, it's worth filling out the little form). There are no real
restrictions on it, aside from the expected "no commercial use" and the
usual crippling (limited levels of recursion and number of tables).

I really like it -- but cK especially makes it interesting.

>-Rod

-Billy

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com.  Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/saFolB/TM
---------------------------------------------------------------------~->

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/concatenative/
(Continue reading)

Stevan Apter | 6 Apr 2004 23:26

Re: [stack] Pattern matching, stack comments


> In addition, as Stevan pointed out, you can also express other patterns,
> such as lists. "ab[cd]--ac[bd]" is a possible example. I like the idea, but
> I can't imagine using it :-). If I did, I'd probably modify it to
> pattern-match against the car and cdr of the list, not against every
> specific item in the list. That way every list pattern would work for ANY
> list, not just the lists with the same length as the pattern.

oh - that's a very nice idea - i hadn't thought of that.  so

    [xy] 

always matches x to the car and y to the cdr?  i like it.  

> 
> >dg
> 
> -Billy
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
(Continue reading)

Tanksley, William D. Jr. | 7 Apr 2004 00:02
Picon
Favicon

RE: [stack] Pattern matching, stack comments

From: Stevan Apter [mailto:sa <at> nsl.com] 
>>probably modify it to pattern-match against the car and cdr of the 
>>list, not against every specific item in the list. That way 
>>every list pattern would work for ANY list, not just the lists 
>>with the same length as the pattern.

>oh - that's a very nice idea - i hadn't thought of that.  so

Oh! Sorry -- I just assumed you had some reason for doing things differently
:-). All the modern pattern-matching languages that incorporate list support
match head and tail.

>    [xy] 
>always matches x to the car and y to the cdr?  i like it.  

Yup, that's it. You can match deeper into list explicitly, so

 [x[yz]]

matches a list at least two items long, or the language designer can provide
shortcuts so that [xyz] will do the same thing (since it's the obvious thing
to do).

Pattern matching is fun. I enjoyed reading about Haskell; it's a very
powerful language with some useful mathematics that apply very strongly to
concatenative languages. See 

http://www.nomaware.com/monads/html/index.html

for a nice tutorial (be warned -- this does assume Haskell knowledge, but I
(Continue reading)

Stevan Apter | 7 Apr 2004 00:21

Re: [stack] Pattern matching, stack comments


----- Original Message ----- 
From: "Tanksley, William D. Jr." <TanksleyJrW <at> saic.com>
To: <concatenative <at> yahoogroups.com>
Sent: Tuesday, April 06, 2004 6:02 PM
Subject: RE: [stack] Pattern matching, stack comments

> From: Stevan Apter [mailto:sa <at> nsl.com]
> >>probably modify it to pattern-match against the car and cdr of the
> >>list, not against every specific item in the list. That way
> >>every list pattern would work for ANY list, not just the lists
> >>with the same length as the pattern.
>
> >oh - that's a very nice idea - i hadn't thought of that.  so
>
> Oh! Sorry -- I just assumed you had some reason for doing things differently
> :-). All the modern pattern-matching languages that incorporate list support
> match head and tail.

but i'm so pre-modern ..

i just think of lists as being "random access" - the head isn't privileged,
"first of x" is just "x 0", &c.

>
> >    [xy]
> >always matches x to the car and y to the cdr?  i like it.
>
> Yup, that's it. You can match deeper into list explicitly, so
>
(Continue reading)


Gmane