News for hackers. Stuff that matters.
Re:More Good Programming Quotes (2016) by tome on Saturday July 22, 2017 @12:43PM (#14828002)
I'm afraid I've never been able to understand macros. What does this do? Is it something like

    greet :: String -> String
    greet "bob" = "Hey bob"
    greet x     = "Greeting, " ++ x

    addmatches :: (String -> String) -> String -> String
    addmatches f = \case
        "emeril" -> "Love the zest"
        "child"  -> "First, we baste the chicken!"
        x        -> f x
If so, you'd have to design it slightly differently to do removematches in Haskell, I guess.
Re:More Good Programming Quotes (2016) by shakna on Saturday July 22, 2017 @06:26PM (#14829777)
Well, it modifies greet in place.

And this:

    greet :: String -> String
Wouldn't really be writable by a human, because:

    x -> f x
Can represent any two expressions, for example:

  (addmatches! greet :chef-matches {:before :beginning}
    ((list? x) :sym) (comment Boolean -> Symbol)
    (list (apply greet x)) (comment Function -> Recursive...))
addmatches! isn't a separate function. Basically, at compile time, a macro is given the raw untyped tokens from Clojure's parser, and can run all of Clojure's features against them. The *match! macros don't exist at runtime.