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

LISP macros in practice

Name: Anonymous 2011-10-23 13:57

A few years of hobbyist cudding and I've yet to find much use for them outside making of generic special loops, of which every permutation of them have been implemented already by library contributors. LISPs aren't shit so boilerplate code doesn't happen, everything else can be made more tidy with lambdas. Has anyone used LISP's most marketable feature (hygienic or not) for anything at the app level?

Name: Mentifex 2011-10-23 14:03

http://groups.google.com/group/comp.lang.lisp/msg/6277b4d4421a424e

is the latest news about the Grand Challenge to port Mentifex AI into Lisp.

Name: Anonymous 2011-10-23 14:09

I used them for defining the possible instructions of a custom assembler. Also, anaphoric macros are quite useful.

Name: Anonymous 2011-10-23 14:11

>>1
Someone should port these macros to C preprocessor.

Name: Anonymous 2011-10-23 14:13

... And why you aren't using it.

1. It's fucking Gay
2. I have no use for gay ass lambda calculus
3. see #1
4. I have no use for monads
5. See #1
6. I don't find the fun in FUNctional programming
7. See #1
8. Did I say it's FUCKING QUEER LIKE A THREE DOLLAR BILL ALREADY!!!

Name: Anonymous 2011-10-23 14:15

>>4
Debugging macros is hard enough as it is. I'd rather write another page of C.

Name: Anonymous 2011-10-23 14:19

>>1
I write small DSLs all the time - not with special syntax, but with special semantics.

Name: Anonymous 2011-10-23 14:21

App-level? DSLs.

Name: FrozenVoid 2011-10-23 14:31

LISP macros are useless because its easier to write inline functions to do anything instead of pages of "magical macros".
Plus i can read the inline function and instantly construct the calling conventions/parameters for another level of nesting so there is enough complexity in page of nested functions to rival any LISP code and they don't need any GC or special syntax.

Name: Anonymous 2011-10-23 14:38

LISP macros are useless because its easier to write inline functions to do anything instead of pages of "magical macros".

I think you're talking out of your ass on this topic. Convince me otherwise.

Name: FrozenVoid 2011-10-23 15:08

>>10
In a syntactically crippled language they might be of use, but i prefer C text macros which are more intuitive and cover 99% of use cases of LISP macros(which can be answered by inline function as i noted in >>9).

Name: Anonymous 2011-10-23 15:10

>>9
Macros are not a replacement for inlining functions (you can declare a function to be inlined in CL), and it's bad form to use macros for that purpose. Their purpose is completly different.

Name: Anonymous 2011-10-23 15:17

The only macro I've used was a convenient way to make an anonymous function that can call itself.


(defmacro rec-lambda (args &rest body)
  `(labels ((this-function ,args
              ,@body))
     #'this-function))

(map 'list (rec-lambda (n)
             (if (<= n 1)
                 1
                 (+ (this-function (- n 1))
                    (this-function (- n 2)))))
           '(1 2 3 4 5 6 7 8 9 10))


I've found passing around functions as arguments to be sufficient for a lot things that people use macros for though.

Name: FrozenVoid 2011-10-23 15:17

>>12
Writing a layer of inline functions is the same as writing layer of lisp macros.

Name: Anonymous 2011-10-23 15:19

>>14
I can show you a lot of things which you can't do using inline functions. Macros just generate code at compile-time: they can generate any kind of code dynamically, while an inline function is merely inserting the body of a function into another function. Lisp macros are not C macros either.

Name: Anonymous 2011-10-23 15:26

>>15

Yeah, one example of something you can get with macros that you can't get with inlined functions is dynamic scope, since the macro can directly manipulate local variables that happen to be defined in the function invoking the macro. I'm not saying this as a good thing to do in general though.

Another thing is that you have the option of deciding when to evaluate the arguments, or to evaluate them multiple times. You can also make your own parser in lisp and transform the arguments syntactically before evaluating them.

Name: FrozenVoid 2011-10-23 15:38

>>16
Nonsense all these can done with simple macros without even resorting to inline functions.
>manipulate local variables that happen to be defined in the function invoking the macro.
#define change(a) (a++)
>when to evaluate the arguments
#define changemacro(a,b) a?change(a):change(b)
>to evaluate them multiple times
#define change (...) //see http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

Name: Anonymous 2011-10-23 15:41

>>15-16
I still don't get how can people fall for FV's trolls.

Name: sage 2011-10-23 15:43

sage

Name: Anonymous 2011-10-23 16:13

Macros are a type system made easy, where you're in full control. No need to fuck with templates or typeclasses, just say directly what you want.

Name: Anonymous 2011-10-23 16:16

Deficient Haskell has no macros and you have to write code like
http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/GHC-Show.html#ShowS

instance  (Show a, Show b) => Show (a,b)  where
  showsPrec _ (a,b) s = show_tuple [shows a, shows b] s

instance (Show a, Show b, Show c) => Show (a, b, c) where
  showsPrec _ (a,b,c) s = show_tuple [shows a, shows b, shows c] s

instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d) where
  showsPrec _ (a,b,c,d) s = show_tuple [shows a, shows b, shows c, shows d] s

instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) where
  showsPrec _ (a,b,c,d,e) s = show_tuple [shows a, shows b, shows c, shows d, shows e] s

instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a,b,c,d,e,f) where
  showsPrec _ (a,b,c,d,e,f) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g)
        => Show (a,b,c,d,e,f,g) where
  showsPrec _ (a,b,c,d,e,f,g) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h)
         => Show (a,b,c,d,e,f,g,h) where
  showsPrec _ (a,b,c,d,e,f,g,h) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i)
         => Show (a,b,c,d,e,f,g,h,i) where
  showsPrec _ (a,b,c,d,e,f,g,h,i) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
                      shows i] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j)
         => Show (a,b,c,d,e,f,g,h,i,j) where
  showsPrec _ (a,b,c,d,e,f,g,h,i,j) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
                      shows i, shows j] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k)
         => Show (a,b,c,d,e,f,g,h,i,j,k) where
  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
                      shows i, shows j, shows k] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,
          Show l)
         => Show (a,b,c,d,e,f,g,h,i,j,k,l) where
  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
                      shows i, shows j, shows k, shows l] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,
          Show l, Show m)
         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m) where
  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
                      shows i, shows j, shows k, shows l, shows m] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,
          Show l, Show m, Show n)
         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where
  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
                      shows i, shows j, shows k, shows l, shows m, shows n] s

instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,
          Show l, Show m, Show n, Show o)
         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where
  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) s
        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
                      shows i, shows j, shows k, shows l, shows m, shows n, shows o] s

Name: Anonymous 2011-10-23 16:34

>>20-21
Macros and type systems are completely different things.

Name: FrozenVoid 2011-10-23 17:03

>>22
Macros provide generic abstraction over the type system like void pointer are the generic(top) type for pointers.
#define add(a,b) a+b
//add()does not know about type of a,b

Name: Anonymous 2011-10-23 17:19

>>23
like void pointer are the generic(top) type for pointers.

That is a big NO there douche. Perhaps you should actually learn one of the ANSI/ISO C standards instead of googling shit. Cripes you suck. Go suck another dick you dildo.

Name: Anonymous 2011-10-23 18:21

>>22
Type system is a very limited and perverted form of macros.

Name: Anonymous 2011-10-23 18:31

>>21
Haskell has macros, they're just not used in the implementation of the standard library.

Name: Anonymous 2011-10-24 3:27

>>23
No, macros and type systems are two completely different and unrelated things. You can have typed macros, see >>26.
Oh, wait, IHBTBFV.

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