a = [10, '10', 10.0] a.sort(lambda x,y: cmp(x.__class__.__name__, y.__class__.__name__)) print a [10.0, 10, '10']
Okay, this doesn't make sense. How do you pass the parameters x and y to the anonymous function? Nowhere in the code does it specify what x and y actually are, or what their values are, or where their values came from.
Also, I've tried using the lambda operator in a Lisp program to conditionally build a function:
( defun fun () ( cond ( ( > var 0 ) ( lambda () ( print "p" ) ) ) ( ( < var 0 ) ( lambda () ( print "n" ) ) ) ( t ( lambda () ( print "z" ) ) ) ) ) )
This evaluates to "FUN", and when I run the function it does nothing (I already declared var by the way).
So what exactly do anonymous functions do? What are they used for, how are they called, and how are parameters passed to them? Can you give me some example code (preferably in Lisp)?


Sign In
Create Account


Back to top









