Scheme master please help

jliao20

Junior Member
Dec 4, 2010
1
0
0
Im writing two scheme , but i run into some problems.. im using Dr.Schme.. and im limited only to use use the following pre-defined Scheme procedures : define, lambda, cond (including the else notation), if, cons, car, cdr, null?, =, equal?, list?, odd?, and, or, not, +, -, *, /, <, <=, >, >=

(calc-running-sums L)
The calc-running-sums function takes a simple list L of numbers and returns a list containing the running sums from L. The nth element in the returned list is the sum of the first n elements in L.
Examples:
(calc-running-sums '(1)) => (list 1)
(calc-running-sums '(2 2 2 2 2)) => (list 2 4 6 8 10)
(calc-running-sums '(2 5 8)) => (list 2 7 15)

(filter-items F L)
The filter-items function takes a function F (which takes one argument and returns a boolean result) and a list L. The job of filter-items is to call F on each of the elements of L, returning a list of all the elements in L for which F returned true, while leaving out all the elements in L for which F returned false. This is a pretty powerful function that can solve a wide variety of problems. (In general, we say that higher-order functions are those that take other functions as arguments. Why they're called "higher-order," and why they're so powerful, is because you can send an arbitrary function to configure them, so that they can solve problems that you haven't even conceived of yet.)
The examples below make use of a few predefined Scheme functions, to show how versatile filter-items will be when you're done with it. Feel free to use these functions in your tests for filter-items, even though they're not on the list of functions you can use in your solutions:

  • positive?, which returns true if its argument is a positive number and false if not
  • odd?, which returns true if its argument is an odd number and false if not
  • string-length, which takes a string as an argument and returns the number of characters in the string
Examples:
(filter-items positive? '(1 -3 2 -4 3 -5 4 -6)) => (list 1 2 3 4) (filter-items odd? '(1 2 3 4 5 6)) => (list 1 3 5) (filter-items is-increasing? '((1 4) (4 3 2) (5 6)) => (list (list 1 4) (list 5 6)) (filter-items (lambda (s) (<= (string-length s) 4)) '("Alex" "is" "happy" "today")) => (list "Alex" "is") im totally lost and i tried so many different combo and it still doesn't work .. any help would be appricated ;]
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Those sound like some fun problems, what have you attempted so far? Nobody here is going to flat out give you any answers, most of us have been in your shoes doing these exact problems at one point. If you give us code that you've already written in an attempt to solve the problem we'll be more likely to help you out and point you towards the right resources to figure out how to solve the problem.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
You know how dumb it is to copy problems verbatim from your homework and post them online? Especially when your post basically asks for the answers?

You should probably contact this guy before I do: thornton@ics.uci.edu
 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0
You know how dumb it is to copy problems verbatim from your homework and post them online? Especially when your post basically asks for the answers?

You should probably contact this guy before I do: thornton@ics.uci.edu

:D I lol'd.

Back on topic... man learning Scheme was awesome. It was my first (and last, so far) functional language. There's so much crazy shit you can do w/functional languages. Our final project involved implementing (not from scratch) a meta-circular evaluator. Programming in C just doesn't have this:

yo-dawg-lisp.jpg
 

nyker96

Diamond Member
Apr 19, 2005
5,630
2
81
:D I lol'd.

Back on topic... man learning Scheme was awesome. It was my first (and last, so far) functional language. There's so much crazy shit you can do w/functional languages. Our final project involved implementing (not from scratch) a meta-circular evaluator. Programming in C just doesn't have this:

yes I remember my final project was also writing a meta eval. kinda brings back memory. But all that paren matching is tough though.

I think OP should work on this on your own or at least have an attempt written out. The best way to understand something is try to use it.
 

dinkumthinkum

Senior member
Jul 3, 2008
203
0
0
yes I remember my final project was also writing a meta eval. kinda brings back memory. But all that paren matching is tough though.

Please don't tell me you wrote code in Notepad. Any reasonably decent programmer's editor will do the matching for you.
 

Daishiki

Golden Member
Nov 9, 2001
1,943
36
91
You know how dumb it is to copy problems verbatim from your homework and post them online? Especially when your post basically asks for the answers?

You should probably contact this guy before I do: thornton@ics.uci.edu

I remember being in a few of Thorton's classes, which I actually enjoyed.