(defmodule leap (export (leap-year 1))) (defun leap-year (year) (and (= (rem year 4) 0) (or (/= (rem year 100) 0) (= (rem year 400) 0)))) I feel like that should work, but I get this error during compile: ffdtm:leap $ rebar compile ==> lfe (compile) ==> lutil (compile) ==> color (compile) ==> ltest (compile) ==> leap (compile) src/leap.lfe:4: unbound function: #(= 2) src/leap.lfe:4: unbound function: #(= 2) Compiling src/leap.lfe failed: ERROR: compile failed while processing ~/exercism.io/lfe/leap: rebar_abort |
= is used in pattern matching.
--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-e...@googlegroups.com.
To post to this group, send email to lisp-flavo...@googlegroups.com.
Visit this group at http://groups.google.com/group/lisp-flavoured-erlang.
For more options, visit https://groups.google.com/d/optout.
Yes, in pattern matching = is used to show aliases, basically that two patterns should match at the same time. It is most commonly used like (= (tuple a b c) t) where they match that the data is a tuple and you bind a, b and c to the elements and it binds t to the whole tuple.Robert
On 30 July 2015 at 22:12, Mason Staugler <ma...@staugler.net> wrote:
= is used in pattern matching.
--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-erlang+unsub...@googlegroups.com.
As an exercise, I've started implementing the various map functions from the CL HyperSpec and ran into a bit of a roadblock their variadic nature.
I know certain functions like the arithmetic operators and ++ are (seem?) variadic, so I'm wondering how I can write my own.
[...]
Related question: Given a defined function, is there a way to get its arity?
As in:
(defun f (x y) (+ x y))
(... f) ; <= 2
proplists:get_value(arity, erlang:fun_info(...)).
--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-e...@googlegroups.com.
(defmacro plus ((x) x) ((x y) `(+ ,x ,y)) ((x y . zs) `(plus (plus ,x ,y) ,@zs)))
On Aug 4, 2015, at 1:50 AM, H Durer <h.du...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-e...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-erlang+unsub...@googlegroups.com.
To post to this group, send email to lisp-flavoured-erlang@googlegroups.com.
Visit this group at http://groups.google.com/group/lisp-flavoured-erlang.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-erlang+unsub...@googlegroups.com.
To post to this group, send email to lisp-flavoured-erlang@googlegroups.com.
Just to confirm what Duncan wrote. When you write a pattern you should write it in the same way as you would write to build the structure so you need to use cons, list or list*. So your macro would become:
(defmacro plus
((list x) x)
((list x y) `(+ ,x ,y))
((list* x y zs) `(plus (plus ,x ,y) ,@zs))
;((cons x (cons y zs)) `(plus (plus ,x ,y) ,@zs)) ;Without macros in the patterns
)
Or to do as Duncan did and used the backquote macro in the patterns as well which expand to the same thing.
Robert
P.S. It is very strange, when viewing directly in google groups I see this message and the other comments to you original message in the exercism.io thread but in my mail I see them under variadic functions. Computers are strange.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-e...@googlegroups.com.
To post to this group, send email to lisp-flavo...@googlegroups.com.