Lee Mac Posted August 14, 2010 Posted August 14, 2010 Can you please explain to me the procedure of codes they are running ? What specifically do you want to know? Quote
Michaels Posted August 14, 2010 Author Posted August 14, 2010 Another couple of 'massoc's as an example: (defun massoc ( x lst ) ;; © Lee Mac 2010 (vl-remove-if-not (function (lambda (pair) (= x (car pair))) ) lst )) (defun massoc ( x lst ) ;; © Lee Mac 2010 (if lst [color="red"];<-How could IF run since lst does not have a value ?[/color] (if (= x (caar lst))[color="red"];<-Also this one (x)[/color] (cons (car lst) (massoc x (cdr lst)))[color="red"];Here is the big issue...[/color] (massoc x (cdr lst))[color="red"];a very blind code to me[/color] ) )) Thanks for valued help LEE. Appreciated. Quote
Lee Mac Posted August 14, 2010 Posted August 14, 2010 To help your understanding, I would suggest that you read around the topic of arguments for functions and how to pass arguments to functions. 'x' and 'lst' represent arguments to be passed to this function (in the same way that Kerry uses 'alist') when the function is called, data is bound to these symbols and then, when referenced, they point to that same data, as if they were used in a 'setq' call. As for the explanation of the workings of the code: (defun massoc ( x lst ) ;; © Lee Mac 2010 (if lst [color=Purple][i][b]; If there is a list[/b][/i][/color] (if (= x (caar lst)) [i][color=Purple][b]; Check the first element of the first dotted pair with the desired item[/b][/color][/i] (cons (car lst)[color=Purple][i][b] ; retain the item[/b][/i][/color] (massoc x (cdr lst))) [i][b][color=Purple]; process the rest of the list recursively[/color][/b][/i] (massoc x (cdr lst)) [b][i][color=Purple]; else process the rest of the list recursively[/color][/i][/b] ) ) ) I would also suggest you read up on recursion, here is perhaps a good starting point: http://pages.cs.wisc.edu/~vernon/cs367/notes/6.RECURSION.html Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.