Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2012, 04:37 PM
Kyndar Kyndar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 Kyndar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 20 sec
Reputation Power: 0
DrRacket help [I need help please]

So i am working on an assignment for school and am pretty confused about racket. I know cond, cons, car, cdr, and a couple other basic operations, but I am having trouble wrapping them together into something useful. my problem is this:

I need to implement a Scheme function, RemoveFirst, that takes as arguments a natural number n and a list L and
removes the fi rst n elements of L. That is, the function returns a new list containing elements (n+1) through
the end of the input list L. If n is greater than the length of L, the function returns the empty list. If n is
negative, the function returns #f.
For example, (RemoveFirst 2 '(fee fi fo fum)) returns '(fo fum).

If someone can show me what this would look like, or give me a push in the right direction that would be super helpful. My biggest issue is getting the syntax right.

Thanks in advance for your time and help!

Reply With Quote
  #2  
Old October 29th, 2012, 06:21 PM
Kyndar Kyndar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 Kyndar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 20 sec
Reputation Power: 0
Heres what i have so far

(define (removefirst n L)
(cond
((< n 0)(#f))
((= n 0)(L))
((> n (length L))(" "))
(else removefirst(- n 1)(cdr L))))

Reply With Quote
  #3  
Old October 30th, 2012, 03:12 AM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,938 Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 h 43 m 16 sec
Reputation Power: 1312
You basically have it, but as you foreshadowed, your syntax is completely wrong. First thing: as an expression, an unquoted list is a function call. Thus, (#f) is not the literal #f, but the function #f (which doesn't exist) evaluated with no arguments. This is an error. Similarly, (L) is not the list L, but the value of L considered as a function and evaluated with no arguments. Next: the empty list is (), not (" ") (which is a singleton list with its one element being a string with one character). Next:
Code:
(else removefirst(- n 1)(cdr L))
does not do what you think it does: when the 'else' clause is reached, the three expressions 'removefirst', '(- n 1)', and '(cdr L)' are evaluated in turn, and the value of (cdr L) is returned as the value of the cond expression. This is not what you want. As I stated earlier (and as you should know, since you used the syntax in your first post), to evaluate removefirst with the two arguments, you use the expression (removefirst (- n 1) (cdr L)). Finally, 'removefirst' and 'RemoveFirst' are not equivalent, since Scheme is case-sensitive.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > DrRacket help [I need help please]

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap