6 Replies - 1226 Views - Last Post: 24 April 2014 - 06:56 PM

#1 name12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-November 12

Common Lisp

Posted 24 April 2014 - 01:42 PM

I am new to lisp language. just 3 days into it.
i have an assignment and i need help in writing the codes.

Write a Lisp function that takes three arguments: a list of integers called aList, an integer called min, and an integer called max. The function returns the number of elements in aList that fall in the range min <= x <=max, where x is an element of aList. If aList is empty, the function should return 0.

So far:
(defun countem(aList, min, max)

I just need guidance not codes!! i want to write the code by myself

Is This A Good Question/Topic? 0
  • +

Replies To: Common Lisp

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2627
  • View blog
  • Posts: 4,182
  • Joined: 21-June 11

Re: Common Lisp

Posted 24 April 2014 - 01:53 PM

First of all you don't use commas to separate parameters in Lisp - just spaces.

Secondly, have you covered remove-if/remove-if-not in class? If so, those are the functions you'd want to be using here. Otherwise you're probably expected to define your function, so that it builds up the desired list recursively.
Was This Post Helpful? 0
  • +
  • -

#3 name12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-November 12

Re: Common Lisp

Posted 24 April 2014 - 02:29 PM

we have not covered that in class. we learn 10 programming languages in 3 months. we just learn some basics.

Is it possible if i can get help in the code. like Pseudo codes. i stuck on it and don't have any idea
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2627
  • View blog
  • Posts: 4,182
  • Joined: 21-June 11

Re: Common Lisp

Posted 24 April 2014 - 02:43 PM

Well, what have you covered? Or maybe I should ask: what are you allowed to use? If you're sprinting through programming languages, maybe you're supposed to read up on stuff yourself and are thus allowed to use functionality that hasn't been covered in class? If so, read up on the functions I mentioned.

If not, have you covered how to build up lists recursively? Like do you know how to use if, how to write recursive functions and how to use [ill]cons[/il]?

Or alternatively: have you learned how / are you allowed to use loop? Because that'd work too.
Was This Post Helpful? 0
  • +
  • -

#5 name12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-November 12

Re: Common Lisp

Posted 24 April 2014 - 06:34 PM

(defun countem(integers min max)
(if (> min max)
( )
(cons min (integers (add1 min) max))))

is this right
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2627
  • View blog
  • Posts: 4,182
  • Joined: 21-June 11

Re: Common Lisp

Posted 24 April 2014 - 06:49 PM

(integers (add1 min) max) calls the function integers with the given arguments - except there is no function named integers, so that doesn't work. I assume you meant to call the countem function with integers and the others as arguments, for which you'd need to add integers to the front of the function call there.

If you fix that, the function should run without error, but it wouldn't really be doing what the assignment is asking of you. You're simply creating a list containing all the numbers between min and max regardless of the contents of integers (note how you're never actually doing anything with integers except passing it around).
Was This Post Helpful? 0
  • +
  • -

#7 name12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-November 12

Re: Common Lisp

Posted 24 April 2014 - 06:56 PM

(defun countem(aList min max)
(if (> min max)
(cons min (aList (add1 min) max))))

ok. how should i return the number of elements between min and max?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1