Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Lisp challenge

Name: Anonymous 2014-09-13 7:11

Lisp macros can do anything, they say. But can they do typeclasses?
For the purpose of feasibility study, I'll simplify the challenge, of course. It will go like this:

Implement the form mappend such that

(mappend 2 3)

expands to

(+ 2 3)

and

(mappend "arst" "neio")

expands to

(concatenate 'string "arst" "neio")

(the above code is in Common Lisp, but you're free to use any Lisp and substitute the corresponding forms from that Lisp).

The expansion must happen no later than compile-time, with no runtime overhead.

Feel free to use Typed Racket, Shen, Arc, Clojure or any other Lisp.

Name: Anonymous 2014-09-13 12:08

(define-syntax mappend
(λ (stx)
(syntax-case stx ()
((_ 2 3) #'(+ 2 3))
((_ a b) (let ((x (syntax->datum #'a))
(y (syntax->datum #'b)))
(and (string? x)
(string? y)
(string=? x "arst")
(string=? y "neio")))
#'(string-concatenate a b)))))


Your ill-defined challenges are the best argument against formal verification I have seen so far, Haskell-kun.

Wouldn't a “proper” (read: handles more than literals) implementation of this require type inference? After all, evaluating the arguments during compile-time defeats the intended purpose of makeshift type classes.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List