This is not a huge deal, and probably a bit out of the order we discussed. I started thinking about pattern matching yesterday, though, and I was trying to do the simple example in fare-matcher (a simple modification of what's in the docs): (defun test-match (param) (fare-matcher:match param (:ping (print :pong)) (:quit (print :bye)) ((:add a b) (print :add))))
Matching with the simple symbols ping and quit works just fine, but things go south when trying to match with add and bind a and b. I was attempting to do: (test-match '(:add 1 2)) But something is wrong in the macroexpansion. Am I even using my test-match function properly? Does match handle quoted sexpr properly or was I just masking this problem with :ping and :quit by handing it symbols that evaluate to themselves?
Also, since I believe both authors are on the list, should I consider using cl-match instead? Or are our pattern matching requirements so minimal that a) it does not matter and b) we could even roll our own ala some of the Norvig examples?
--matt
On Fri, May 30, 2008 at 09:05:39AM -0500, Matt Bone wrote:
This is not a huge deal, and probably a bit out of the order we discussed. I started thinking about pattern matching yesterday, though, and I was trying to do the simple example in fare-matcher (a simple modification of what's in the docs): (defun test-match (param) (fare-matcher:match param (:ping (print :pong)) (:quit (print :bye)) ((:add a b) (print :add))))
that should be (list :add a b)
2008/5/30 Stelian Ionescu sionescu@common-lisp.net:
On Fri, May 30, 2008 at 09:05:39AM -0500, Matt Bone wrote:
This is not a huge deal, and probably a bit out of the order we discussed. I started thinking about pattern matching yesterday, though, and I was trying to do the simple example in fare-matcher (a simple modification of what's in the docs): (defun test-match (param) (fare-matcher:match param (:ping (print :pong)) (:quit (print :bye)) ((:add a b) (print :add))))
that should be (list :add a b)
Or alternatively, `(:add ,a ,b) using fare-quasiquote (that I don't recommend at this point, because its support for nested ,@ is buggy and necessitates a rewrite).
[ François-René ÐVB Rideau | Reflection&Cybernethics | http://fare.tunes.org ] The American Republic will endure, until politicians realize they can bribe the people with their own money. -- Alexis de Tocqueville
Matt Bone wrote:
are our pattern matching requirements so minimal that a) it does not matter and b) we could even roll our own ala some of the Norvig examples?
According to one of the tutorials[*], Erlang patterns support variable repetition. I think Fare mentioned using existing Erlang test code, so that might be an issue.
--Dan
[*] http://www.erlang.org/course/sequential_programming.html#patterns
------------------------------------------------ Dan Bensen http://www.prairienet.org/~dsb/
cl-match: expressive pattern matching in Lisp http://common-lisp.net/project/cl-match/
2008/6/1 Dan Bensen dsb@prairienet.org:
Matt Bone wrote:
are our pattern matching requirements so minimal that a) it does not matter and b) we could even roll our own ala some of the Norvig examples?
According to one of the tutorials[*], Erlang patterns support variable repetition. I think Fare mentioned using existing Erlang test code, so that might be an issue.
Excuse my ignorance here but what exactly are you planning to use the pattern matching for? If it is for use in the code to which you compile Erlang then I would seriously think through how you are compiling Erlang.
Yes, Erlang supports variable repetition (with implicit checking of values) and also non-lexical scoping so using and already bound variable in a pattern also means an implicit comparison of values.
I would not directly compile the Erlang code to lisp but would use the first few passes of the Erlang compiler. This would ensure compatibility with existing Erlang for many features (records, list/binary comprehensions) and be much easier as the internal languages are much simpler.
I would suggest using Core Erlang or even kernel Erlang. Core is a very simple functional language which has lexical scoping and simplified pattern matching. Kernel erlang has been fully lambda lifted and is completely "flat" and pattern matching has been compiled and optimised to basic tests.
In a follow up to this mail I will send a copy of a presentation of LFE (Lisp Flavoured Erlang) I gave which I think would be interesting in 2 respects:
- the LFE core forms are *very* close to Core Erlang (almost 1-to-1) - there is a *short* description of the compiler at the end, only 3 slides but it at least presents the passes and some of the internal languages.
It's 87 kB Powerpoint document so I apologise for sending big message. Unfortunately I can't convert it to PDF, if anyone can help with this I would appreciate it.
Robert
erlang-in-lisp-devel@common-lisp.net