Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Kotoshov

Hi, 1) How do you change the order of a list according to some property (e.g. decreasing order)? 2) How to evaluate the following expressions? (in the same environment) (+ '1 '2) '(+ 1 3) '(a (b (c (d)))) (define x 3) 'x (define a x) 'a (define b 'x) b 'b (quote (quote a)) ''a Thanks, I'm really lost in evaluations!

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. Kotoshov
    Best Response
    You've already chosen the best response.
    Medals 0

    To be exact, my question is why we evaluate them the way we do? I don't get the rules of evaluation for tagged data.

    • 2 years ago
  2. calmchessplayer
    Best Response
    You've already chosen the best response.
    Medals 0

    what language is this?

    • 2 years ago
  3. Kotoshov
    Best Response
    You've already chosen the best response.
    Medals 0

    Umm Scheme of course. That's the language of the course.

    • 2 years ago
  4. calmchessplayer
    Best Response
    You've already chosen the best response.
    Medals 0

    I can't help you I don't program in that low level of a language I think Lisp is in that category as well People do consider you a major geek if you know Lisp or Scheme though. These languages are good for processing mathmatical data and maybe statistical data I can just think of easier ways to do what you want to do with higher level <what I call > 5th and 6th generation languages. What hardware and O/S do you plan to run your program on ? Objective-C, JAVA, ActionScript 3.0, PHP, or Python even might be a better choice for you to learn CORE programming techniques on after u learn core you will be able to better use just about any API or programming language out the CORE doesn't really change just the methods and techniques to reach your "final output/dynamic output changes." I've wrote some extremely complex programs that only contain 6000 lines of code in ActionScript but Actionscript is dying so I plan to port all my stuff to Objective-C and Coca and run my programs on Apple/IOS devices. This is my opnion take it with a grain of salt. I will never know all there is to know about programming. I don't know what I'm doing all I know is I don't want to stop --Ozzy Osbourn

    • 2 years ago
  5. sarabander
    Best Response
    You've already chosen the best response.
    Medals 1

    ;; 1) ;; You could use sort with a comparison function. like < or >: ;; ascending: (sort '(8 5 14 7 3) <) ; '(3 5 7 8 14) ;; descending: (sort '(8 5 14 7 3) >) ; '(14 8 7 5 3) ;; When dealing with strings, use string<? or string>? in place of < or >: (sort '("Ga" "Ag" "Cu" "Fe" "Xe") string<?) ; '("Ag" "Cu" "Fe" "Ga" "Xe") (sort '("Ga" "Ag" "Cu" "Fe" "Xe") string>?) ; '("Xe" "Ga" "Fe" "Cu" "Ag") ;; To sort a list of symbols, you can convert them to strings, then sort, ;; then convert back to symbols: (map string->symbol (sort (map symbol->string '(tau xi gamma mu rho)) string>?)) ; '(xi tau rho mu gamma) ;; There are no functions named symbol<? and symbol>? in Racket (but there is ;; symbol=?), so you could just define them: (define (symbol<? a b) (string<? (symbol->string a) (symbol->string b))) (define (symbol>? a b) (string>? (symbol->string a) (symbol->string b))) (sort '(xi tau rho mu gamma) symbol<?) ; '(gamma mu rho tau xi) (sort '(xi tau rho mu gamma) symbol>?) ; '(xi tau rho mu gamma) ;; ------------------------------------------------------- ;; 2) ;; I give the response in comment after the expression. ;; Quoted numbers are evaluated to themselves, there's no difference ;; between 2 and '2 in Scheme: (+ '1 '2) ; 3 ;; This is just quoted list, + is treated like '+ (not evaluated): '(+ 1 3) ; '(+ 1 3) ;; If you need to evaluate quoted lists: (eval '(+ 1 3)) ; 4 ;; But the first element of list must be procedure, this gives error: (eval '(4 1 3)) ; procedure application: expected procedure, given: 4 ;; Just quoted list of nested lists of symbols: '(a (b (c (d)))) ; '(a (b (c (d)))) ;; Here you bind the symbol x to 3: (define x 3) 'x ; 'x (eval 'x) ; 3 ;; Here you just copy the address of 3 and bind it to a. ;; Now both x and a point to 3 (a is not pointing to the symbol x): (define a x) 'a ; 'a a ; 3 ;; Binds b to literal symbol x, not to the cell named x (which holds 3): (define b 'x) b ; 'x 'b ; 'b ;; If you want back the value pointed by a, use eval twice: (quote (quote a)) ; ''a ''a ; ''a (eval ''a) ; 'a (eval (eval ''a)) ; 3 ;; Quoting in Scheme is good for passing around the names of bindings ;; instead of the values they point to. This is analogous to ;; quotes in written text. There's a difference between "Say your name!" ;; and "Say 'your name'!" (See lecture 3B, at 18:10): http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/video-lectures/3b-symbolic-differentiation-quotation/

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.