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

Pages: 1-4041-

Trouble with CLISP

Name: The informer 2009-04-20 0:22

So basically I'm taking a programming languages class and we are working on functional languages right now.  But our class and book have been teaching  us everything in scheme and yet our professor in his infinite wisdom decided to have us do an assignment in emacs CLISP.  I am having a retardedly difficult time getting this to work I think primarily because of the syntax but I've also been getting errors when I call the function as well.

The tasks are as follows

Creating a function that returns the number of zeros in a given simple list of numbers

A function that deletes all the top level instances of an atom from a list

a function that returns the union of two simple list parameters that represent sets

and a function that has 2 parameters an atom and a list that returns the list with all occurrences of the atom deleted.

I solved the first two in scheme and sadly can not port it over to clisp properly and I gave up after about 2 hours of working on the first two. 

Here is the scheme code for the first 2.

(define (x lis)
    (cond
       ((null? lis) 0)
       ((eq? 0 (car lis)) (+ 1 (x (cdr lis)))
       (else (+ 0 (x (cdr lis)))
     )
)

(define (x atom lis)
     (cond
       ((null? lis) '() )
       ((eq? atom lis) (x atom cdr(lis)))
       ((else (cons car(atom) (x atom cdr(lis)))))
     )
)

Any and all help  is appreciated.

Name: Anonymous 2009-04-20 2:29

(defun zeroes (lst)
  (cond
    ((not lst) 0)
    ((= 0 (car lst)) (+ 1 (zeroes (cdr lst))))
    (t (+ 0 (zeroes (cdr lst))))))

Name: Anonymous 2009-04-20 3:05

>>1
Your C-style paren indentation is fucking rage inducing.

Name: Anonymous 2009-04-20 4:32

>>1
emacs CLISP
I found your problem: there is no such fucking thing. Also your code is in Skiim.

Name: Anonymous 2009-04-20 4:35

LISP is not functional languages.

Name: Anonymous 2009-04-20 4:41

>>4
http://www.red-bean.com/guile/notes/emacs-lisp.html

>>5
http://en.wikipedia.org/wiki/Functional_programming

>An early functional-flavored language was LISP, developed by John McCarthy while at MIT for the IBM 700/7000 series scientific computers in the late 1950s.[14] LISP introduced many features now found in functional languages, though LISP is technically a multi-paradigm language. Scheme and Dylan were later attempts to simplify and improve LISP.

Name: Anonymous 2009-04-20 4:51

Here, I've ported the first two to Common Lisp. This should make it clear how to proceed.

(defmacro cdrq (list)
  `(setq ,list (cdr ,list)))

(defun zeros (numbers)
  (prog ((zeros 0))
   loop
       (when (zerop (car numbers)) (incf zeros))
       (cdrq numbers)
       (when numbers (go loop))
       (return zeros)))

(defun w/o (atom list)
  (prog (l)
   loop
       (let ((a (car list)))
         (unless (eql atom a) (push a l)))
       (cdrq list)
       (when list (go loop))
       (return (nreverse l))))

Name: Anonymous 2009-04-20 4:53

Name: Anonymous 2009-04-20 10:46

>>6
Emacs Lisp and Common Lisp are two different things. There is no such thing as ``emacs CLISP''.

IHBT

Name: Anonymous 2009-04-20 13:19

>>9
Every ANSI C compiler is required to support at least 32 levels of nested parentheses in an expression.

Name: Anonymous 2009-04-20 13:28

>>10
Ok.

Name: Anonymous 2009-04-20 13:34

>>10
And that's one of the reasonable limits, my favourites are:
8 nesting levels for #include'd files
* 6 significant initial characters in an external identifier

BRB, changing source files to maximum include depth of eight and renaming all extern variables to six characters.

Name: Anonymous 2009-04-20 13:36

>>12
But at least you can safely pass 31 arguments to functions.

Name: The informer 2009-04-21 2:11

OK so I'm still working on this and have gotten pretty much nowhere...  I have the following function for the 4th function and I feel like this should work but it's not going into any of the sub functions.  This is what the terminal looks like.

Break 66 [67]> (defmacro cdrq (list) `(setq ,list (cdr ,list)))
CDRQ
Break 66 [67]> (defun w/o (atom list)
  (prog (l)
   loop
       (let ((a (car list)))
         (if (listp a) (w/o atom a))
         (unless (eql atom a) (push a l)))
       (cdrq list)
       (when list (go loop))
       (return (nreverse l))))
W/O
Break 66 [67]> (w/o 1 (list 1 3 5 (list 1 64 (list 1 76))))
(3 5 (1 64 (1 76)))
Break 66 [67]>

For the third one

(defun uni(lst lis)
(prog (1)
   loop
      (let ((a (car lst))))
      (let ((b (car lis))))
      (when lst ((push a 1) (cdrq lst) (go loop)))
      (when lis ((push b 1) (cdrq lis) (go loop)))
      (return (nreverse 1))))

This won't give me a return and says (PUSH A 1) should be a lambda expression.

Help please?

Name: Anonymous 2009-04-21 3:03

>>14
(PUSH A 1) should be a lambda expression if you want to put it where you did. The car of a form to be evaluated needs to be a function, so (when lst ((push a 1) is bullshit. What you need to write is (when lst (progn (push a 1). Except (as you would know if you bothered to read the documentation instead of just fucking guessing), the body of a WHEN is an implicit progn so you can drop it entirely.

Also you appear to be attempting to create a variable called "1" (one). Why would you do that? Also LET doesn't work the way you think it does (look it up). Also LET can be used to bind any number of variables, so you don't need two. Also YHBT, but I'll leave it to you to figure out why.

Name: Anonymous 2009-04-21 3:06

>>10,12
wrong.
63 nesting levels of parenthesized expressions within a full expression
15 nesting levels for #included files
31 significant initial characters in an external identifier

Name: Anonymous 2009-04-21 3:18

oh, and
>> 13
127 arguments in one function call

Name: Anonymous 2009-04-21 3:21

>>16
He said ANSI C fuckwit, go back to your cave.

Name: Anonymous 2009-04-21 4:02

>>18
that is ANSI C, and has been for almost 9 years. go back to your cave.

Name: Anonymous 2009-04-21 4:10

>>19
In a casual setting "ANSI C" refers to C89, somebody that wishes to refer to C99 will simply say "C99".

Name: Anonymous 2009-04-21 4:26

>>20
referring to C89 as "ANSI C" has been wrong for 9 years.

Name: Anonymous 2009-04-21 4:27

>>20
When I think of ANSI C, I think of the latest standard, C99.

Name: Anonymous 2009-04-21 4:52

>>22
C89
In 1983, the American National Standards Institute formed a committee, X3J11, to establish a standard specification of C. After a long and arduous process, the standard was completed in 1989 and ratified as ANSI X3.159-1989 "Programming Language C." This version of the language is often referred to as "ANSI C", or sometimes "C89" (to distinguish it from C99).
[...]
C99 Main article: C99
In March 2000, ANSI adopted the ISO/IEC 9899:1999 standard. This standard is commonly referred to as C99, and it is the current standard for C programming language.1

__________
References
1. http://en.wikipedia.org/wiki/ANSI_C

Name: Anonymous 2009-04-21 4:53

>>22
When I think of C99 I think of Microsoft, who have just about the only compiler team of any significance who aren't at least making an effort to implement C99. It's just so laughably pathetic.

Name: Anonymous 2009-04-21 4:56

>>24
It may not implement C99, but most people except their C code to be C89, and some of the useful parts you might want from C99 are implemented in the SEPPLES mode.

Name: Anonymous 2009-04-21 8:05

My other car is a CD-R

Name: Anonymous 2009-04-21 8:22

>>21
a) It's not wrong, and never will be. `C89' is still an ANSI standard specifying the C programming language.
b) I've never heard anyone refer to C99 `ANSI C' before this silly thread.

Name: Anonymous 2009-04-21 10:46

>>1
ha.ha.  more like CLIT am i rite.

Name: Anonymous 2009-04-21 22:33

All Lisp code posted on /prog/ should make use of PROG.

Name: Anonymous 2009-04-22 0:06

>>28
CLISP = Common LISP
I'm not sure what CLIT is though

Name: Anonymous 2009-04-22 0:13

>>30
CLISP = Common LISP
Absolutely not!

Name: Anonymous 2009-04-22 0:42

CLISP is just an obsolete version of /prog/'s favorite the toy procedural language, scheme.

Name: Anonymous 2009-04-22 1:20

>>32
favorite the toy

Name: Anonymous 2009-04-22 1:21

toy language
scheme [sic]

You take that back!

Name: Anonymous 2009-04-22 1:30

The answers in a Lisp-like dialect that's actually useful: newLISP

(define (count-zeros lst)
    (first (count '(0) lst)))

(define (combine-lists lst1 lst2)
    (append lst1 lst2))

(define (filter-atom atom lst)
    (filter (fn (x) (!= x atom)) lst))

Name: Anonymous 2009-04-22 1:42

>>3
listen to this man. to properly program lisp, you must continue to do all the same things like they have for the last 50 years, regardless of how much more useful another method could be.

Name: Anonymous 2009-04-22 11:46

And here it is in elegant bArc

(= (cnt-0s lst) (fst (cnt '(0) lst)))
(= (combine-lists lst1 lst2) (app lst1 lst2))
(= (ftr-atm atm lst) (ftr [!= _ atom] lst))

Name: Anonymous 2009-04-22 12:18

>>36
There are solid reason why one must indent(or autoindent it using emacs) their LISP code, such as enhancing readability, and allowing people to spend much less time reading your code. Someone once wrote a 2 page essay on this topic.

Name: Anonymous 2009-04-22 15:22

>>35
newLISP
D:

Name: Anonymous 2009-04-23 6:46

(hax)(((my))anus)

Name: Anonymous 2009-04-23 21:45

>>40
((hax)(((my))anus)

Name: Anonymous 2009-04-23 21:47

this post was made during sex

Name: Anonymous 2010-11-14 17:57

Name: Anonymous 2010-11-25 8:43

Name: Anonymous 2010-12-06 9:56

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-02-04 17:37

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