Bluish Coder

Programming Languages, Martials Arts and Computers. The Weblog of Chris Double.


2007-01-03

Implementing concatenative words with Pattern Matching

There's a dicussion on the concatenative mailing list about concatenative languages and macros. The discussion veered into pattern matching and Manfred Von Thun wrote about using pattern matching to implement common concatenative operations.

I wrote previously about using pattern matching in Factor to do similar, calling the word 'shuffle'. For example, 2dup, could be implemented as:

{ ?a ?b } { ?a ?b ?a ?b } shuffle

I didn't think of it at the time but Manfred's article prompted me to try doing 'cons' and similar operations that actually have to look inside data structures. Since pattern matching does this already, 'shuffle' does it as well. For example, curry could be:

: my-curry { ?a [ ?b ] } { [ ?a ?b ] } shuffle ;
"hello" [ print ] my-curry .
! => [ "hello" print ]

Tags


This site is accessable over tor as hidden service 6vp5u25g4izec5c37wv52skvecikld6kysvsivnl6sdg6q7wy25lixad.onion, or Freenet using key:
USK@1ORdIvjL2H1bZblJcP8hu2LjjKtVB-rVzp8mLty~5N4,8hL85otZBbq0geDsSKkBK4sKESL2SrNVecFZz9NxGVQ,AQACAAE/bluishcoder/-61/


Tags

Archives
Links