Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Help wiht LISP Function (Newbie)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tortolo  
View profile  
 More options Oct 22 2001, 3:14 pm
Newsgroups: comp.lang.lisp
From: jcard...@ecopetrol.com.co (Tortolo)
Date: 22 Oct 2001 12:14:47 -0700
Local: Mon, Oct 22 2001 3:14 pm
Subject: Help wiht LISP Function (Newbie)
I nee a LISP function, which takes two parameters and returns T if
both parameters are atoms and the value of the first parameter is
greater than the value of the second, otherwise it returns nil. This
LISP function, takes a simple list of numbers as a single parameter,
and returns the maximum value in the list.

Thanks,

Tortolo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marc Spitzer  
View profile  
 More options Oct 22 2001, 3:25 pm
Newsgroups: comp.lang.lisp
From: m...@oscar.eng.cv.net (Marc Spitzer)
Date: Mon, 22 Oct 2001 19:25:36 GMT
Local: Mon, Oct 22 2001 3:25 pm
Subject: Re: Help wiht LISP Function (Newbie)

In article <26176b48.0110221114.7c6ba...@posting.google.com>, Tortolo wrote:
> I nee a LISP function, which takes two parameters and returns T if
> both parameters are atoms and the value of the first parameter is
> greater than the value of the second, otherwise it returns nil. This
> LISP function, takes a simple list of numbers as a single parameter,
> and returns the maximum value in the list.

> Thanks,

> Tortolo

is this your home work?  it realy looks like home work.

marc


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Margolin  
View profile  
 More options Oct 22 2001, 3:26 pm
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@genuity.net>
Date: Mon, 22 Oct 2001 19:26:44 GMT
Local: Mon, Oct 22 2001 3:26 pm
Subject: Re: Help wiht LISP Function (Newbie)
In article <26176b48.0110221114.7c6ba...@posting.google.com>,

Tortolo <jcard...@ecopetrol.com.co> wrote:
>I nee a LISP function, which takes two parameters and returns T if
>both parameters are atoms and the value of the first parameter is
>greater than the value of the second, otherwise it returns nil. This

Not all atoms have an obvious ordering relationship?  For instance, if one
atom is a number and the other is a symbol, how do you determine which one
is "greater"?  Even if you require both atoms to be the same type, what
about things like 2-dimensional arrays?

Did you really mean "both parameters are numbers"?  In that case, isn't the
built-in > function what you want?  You can use IGNORE-ERRORS to return NIL
if both parameters aren't numbers.

>LISP function, takes a simple list of numbers as a single parameter,
>and returns the maximum value in the list.

I thought you just needed one function.  This seems to be a different
function, although it would make use of the first function.  Take a look at
the REDUCE and MAX functions.

BTW, it's considered polite to tell us if you're asking for help with
homework.  And if so, you should show what you tried so that we could
critique it, rather than expecting us to simply do your work for you.

--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Coby Beck  
View profile  
 More options Oct 22 2001, 3:27 pm
Newsgroups: comp.lang.lisp
From: "Coby Beck" <cb...@mercury.bc.ca>
Date: Mon, 22 Oct 2001 19:27:43 GMT
Local: Mon, Oct 22 2001 3:27 pm
Subject: Re: Help wiht LISP Function (Newbie)

"Tortolo" <jcard...@ecopetrol.com.co> wrote in message

news:26176b48.0110221114.7c6ba0c6@posting.google.com...

> I nee a LISP function, which takes two parameters and returns T if
> both parameters are atoms and the value of the first parameter is
> greater than the value of the second, otherwise it returns nil. This
> LISP function, takes a simple list of numbers as a single parameter,
> and returns the maximum value in the list.

There isn't one.  You'll have to write it.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jrm  
View profile  
 More options Oct 22 2001, 3:31 pm
Newsgroups: comp.lang.lisp
From: j...@itasoftware.com
Date: 22 Oct 2001 15:31:46 -0400
Local: Mon, Oct 22 2001 3:31 pm
Subject: Re: Help wiht LISP Function (Newbie)

jcard...@ecopetrol.com.co (Tortolo) writes:
> I nee a LISP function, which takes two parameters and returns T if
> both parameters are atoms and the value of the first parameter is
> greater than the value of the second, otherwise it returns nil. This
> LISP function, takes a simple list of numbers as a single parameter,
> and returns the maximum value in the list.

Facetious answer:

(defun weird (a &optional (b nil b-supplied-p))
   (ignore-errors
     (if (not b-supplied-p)
         (reduce #'max a)
         (> a b))))

This does what you said, but I doubt it is what you want.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tortolo  
View profile  
 More options Oct 23 2001, 5:23 pm
Newsgroups: comp.lang.lisp
From: jcard...@ecopetrol.com.co (Tortolo)
Date: 23 Oct 2001 14:23:56 -0700
Local: Tues, Oct 23 2001 5:23 pm
Subject: Re: Help wiht LISP Function (Newbie)

My Function is:

(define maxlist (list)
  (apply #'max list))

(maxlist '(1 2 3 4 3 2 1)) => 4

Thanks,

Tortolo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas F. Burdick  
View profile  
 More options Oct 23 2001, 5:39 pm
Newsgroups: comp.lang.lisp
From: t...@tornado.OCF.Berkeley.EDU (Thomas F. Burdick)
Date: 23 Oct 2001 14:39:16 -0700
Local: Tues, Oct 23 2001 5:39 pm
Subject: Re: Help wiht LISP Function (Newbie)

First, does the above work in any languge?  (define ...) looks like
scheme, but (apply #'max ...) looks like lisp.

Second, assuming you meant (defun ...), that won't work for lists of
arbitrary length:

 [1]> (defun maxlist (list) (apply #'max list))
 MAXLIST
 [2]> (maxlist (loop for x from 1 to (1+ call-arguments-limit)
                     collect x))

The above will give you an error (although you'll probably run out of
memory first, if you're using CLISP.  CALL-ARGUMENTS-LIMIT is
4294967296 in my copy!)

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Mincy  
View profile  
 More options Oct 23 2001, 8:02 pm
Newsgroups: comp.lang.lisp
From: Jeff Mincy <j...@delphioutpost.com>
Date: 23 Oct 2001 19:55:36 -0400
Local: Tues, Oct 23 2001 7:55 pm
Subject: Re: Help wiht LISP Function (Newbie)
t...@tornado.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

> jcard...@ecopetrol.com.co (Tortolo) writes:

> > j...@itasoftware.com wrote in message <news:g08bzd25.fsf@itasoftware.com>...
> > My Function is:

> > (define maxlist (list)
> >   (apply #'max list))

(reduce #'max list) would be better.  Of course, neither of these answer
the original question of having two argument function.

The call-arguments-limit constant is entirely overrated.

A value of 4294967296 in clisp means that the implementors:
1) probably push arguments on a stack and stacks are addressed with 32
   bit ints.
2) did not do anything in the implementation to restrict the number of
   arguments.
3) had no idea what to do with this 'constant' because it is really a
   function that depends on the current stack depth and the size of
   the stack, and what other programs are running on the machine.
4) made up an answer of 2^32 (which is wrong, if they push a return
   address on the stack).

-jeff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher Stacy  
View profile  
 More options Oct 24 2001, 4:16 pm
Newsgroups: comp.lang.lisp
From: Christopher Stacy <cst...@spacy.Boston.MA.US>
Date: Wed, 24 Oct 2001 20:15:57 GMT
Local: Wed, Oct 24 2001 4:15 pm
Subject: Re: Help wiht LISP Function (Newbie)
 Tortolo> I nee a LISP function, which takes two parameters and returns T if
 Tortolo> both parameters are atoms and the value of the first parameter is
 Tortolo> greater than the value of the second, otherwise it returns nil. This
 Tortolo> LISP function, takes a simple list of numbers as a single parameter,
 Tortolo> and returns the maximum value in the list.

Is this your homework?

The problem description is poorly worded, but I think I can guess
what is being asked for.  Will you first tell is the name of the
school where this is being taught, what book you're using,
which implementation of Lisp (if you know),
and provide the original problem description?

Meanwhile, I'll comment on the function you provided.

 Tortolo> (define maxlist (list)
 Tortolo>   (apply #'max list))

Calling              (APPLY #'F (LIST 1 2 3 4))
is the same as       (F 1 2 3 4)

Based on the problem description, I think you're supposed to
be learning about: writing one function that calls another,
certain built-in functions, return values and boolean
truth values, passing arguments, what lists are, and something
about how to do one or more of: mapping, iteration, or recursion.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas F. Burdick  
View profile  
 More options Oct 24 2001, 4:50 pm
Newsgroups: comp.lang.lisp
From: t...@apocalypse.OCF.Berkeley.EDU (Thomas F. Burdick)
Date: 24 Oct 2001 13:50:01 -0700
Local: Wed, Oct 24 2001 4:50 pm
Subject: Re: Help wiht LISP Function (Newbie)

Jeff Mincy <j...@delphioutpost.com> writes:
> The call-arguments-limit constant is entirely overrated.

> A value of 4294967296 in clisp means that the implementors:

But of course, not every CL has an insanely huge CALL-ARGUMENTS-LIMIT.
I agree that it can be reasonable to assume that you can apply a
sufficiently huge number of arguments, if that's the reasonable way to
solve whatever problem you're solving.  In a case where REDUCE is
screaming to be used, though, it's silly not to use it.  If you do use
APPLY for something like this, it certainly behooves you do document
the possible limitation so as not to give future porters unnecessary
headaches.  And that, to me, sounds like more of a pain in the butt
than just using REDUCE.

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Oct 25 2001, 7:36 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.net>
Date: Thu, 25 Oct 2001 11:36:26 GMT
Local: Thurs, Oct 25 2001 7:36 am
Subject: Re: Help wiht LISP Function (Newbie)
* Thomas F. Burdick
| But of course, not every CL has an insanely huge CALL-ARGUMENTS-LIMIT.

  apply and reduce exhibit the same weird design problem exhibited by Unix
  systems that still have ridiculously small argument list limits because
  core memory was expensive back in the 1840's or whenever.  Especially
  Linux, which in this regard still thinks it runs on Linus's first Amgia
  or whatever.  Most Unices support 64-bit file offsets and 32-bit inode
  numbers, some even 32-bit user ids, but several still argue against more
  than 128K of argument list space, which makes many otherwise natural
  shell wild-card expansions impossible, makes it impossible to use the
  output of commands impossible to use as argument lists, etc.  I patch
  every Linux kernel I install anywhere to increase that limit to 4M, but
  it is such a braindamaged thing to make so small.

  Common Lisp argument lists are different from shell argument lists in one
  crucial respect: You can pass a list as one argument.  This obviates the
  need for most of the operations that take a huge argument list.  Indeed,
  it is good coding practice to accept arbitrary-sized lists as lists, not
  as &rest arguments, since they would have to be spread and collected, and
  really bad coding practice to take some user input and give it to an
  internal function that does not do the user-interface error checking that
  a consumer of user input should do, but given all this, the value should
  at least be so large that a programmer can feel safe when constructing
  argument lists in programs.

  The standard requires that call-arguments-limit be no smaller than 50.

  I would argue that an implementation of Common Lisp that does not allow
  at least 500 arguments is useless, so this is a quality-of-implementation
  issue, but it is not just call-arguments-limit, lambda-parameters-limit
  and multiple-values-limit are also way too small (50 and 20) as specified.

| If you do use APPLY for something like this, it certainly behooves you do
| document the possible limitation so as not to give future porters
| unnecessary headaches.  And that, to me, sounds like more of a pain in
| the butt than just using REDUCE.

  I think it would be a good idea for an application to document its
  requirements on the Common Lisp implementation as far as these limits go,
  since they are only _required_ to be really small.

///
--
  Norway is now run by a priest from the fundamentalist Christian People's
  Party, the fifth largest party representing one eighth of the electorate.
--
  The purpose of computing is insight, not numbers.   -- Richard Hamming


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kent M Pitman  
View profile  
 More options Oct 25 2001, 8:53 am
Newsgroups: comp.lang.lisp
From: Kent M Pitman <pit...@world.std.com>
Date: Thu, 25 Oct 2001 12:51:57 GMT
Local: Thurs, Oct 25 2001 8:51 am
Subject: Re: Help wiht LISP Function (Newbie)

Erik Naggum <e...@naggum.net> writes:
>   Common Lisp argument lists are different from shell argument lists in one
>   crucial respect: You can pass a list as one argument.  This obviates the
>   need for most of the operations that take a huge argument list.  Indeed,
>   it is good coding practice to accept arbitrary-sized lists as lists, not
>   as &rest arguments, since they would have to be spread and collected, and
>   really bad coding practice to take some user input and give it to an
>   internal function that does not do the user-interface error checking that
>   a consumer of user input should do, but given all this, the value should
>   at least be so large that a programmer can feel safe when constructing
>   argument lists in programs.

Actually, for a function that takes an &REST argument, ESPECIALLY one that
takes a SINGLE &REST argument, it seems to me that APPLY should have been
defined to exceed CALL-ARGUMENTS-LIMIT since the list should just be directly
bindable to the rest variable.  I don't see spreading it onto the stack and
then re-composing it to a list.  It's probably worth testing it for dottedness
and circularity, but that can be done faster than consing.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Oct 25 2001, 10:39 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.net>
Date: Thu, 25 Oct 2001 14:39:01 GMT
Local: Thurs, Oct 25 2001 10:39 am
Subject: Re: Help wiht LISP Function (Newbie)
* Kent M Pitman <pit...@world.std.com>
| Actually, for a function that takes an &REST argument, ESPECIALLY one that
| takes a SINGLE &REST argument, it seems to me that APPLY should have been
| defined to exceed CALL-ARGUMENTS-LIMIT since the list should just be directly
| bindable to the rest variable.  I don't see spreading it onto the stack and
| then re-composing it to a list.

  This is only possible in a context where the compiler knows enough about
  the called function when it prepares the call to utilize this information.

  To make this generally available functionality would mean that apply
  would have to ask (the system about) the function whether it would like
  the arguments spread or not, but the function must also be prepared to
  accept individual arguments since that would be what a normal function
  call would have to provide, unless it went through a more expensive
  function call trampoline or something.

///
--
  Norway is now run by a priest from the fundamentalist Christian People's
  Party, the fifth largest party representing one eighth of the electorate.
--
  The purpose of computing is insight, not numbers.   -- Richard Hamming


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »