Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

sicp

Name: sicp 2008-08-31 11:25

Yes I am reading sicp.

(define ex1.2 (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
                 (* 3 (- 6 2)(- 2 7)))
  )

;sumofsquaresoflargest: # # # -> #
;takes three #'s & returns sum of the squares of the two largest
(define (sumofsquaresoflargest a b c)
  (+ (* (largest1 a b c)(largest1 a b c))
     (* (largest2 a b c)(largest2 a b c))))

;largest1: # # # -> #
;takes three numbers and returns the largest
(define (largest1 a b c)
  (cond [(and (> a b)(> a c)) a]
        [(and (> b a)(> b c)) b]
        [(and (> c a)(> c b)) c]
        [else a]))

;largest2: # # # -> #
;takes three numbers and returns the 2nd largest
(define (largest2 a b c)
  (cond [(and (> a b)(< a c)) a]
        [(and (> b a)(< b c)) b]
        [(and (> c a)(< c b)) c]
        [else a]))

;In normal order it would just loop infinitely trying to substitute (p) for (p) looking for a primitive operation to perform. Applicative would evaluate it as 0 by just evaluating (= x 0) as 0 and return 0.

Name: Sageing fail since 1463 2008-08-31 11:58

fail.

Name: Anonymous 2008-08-31 12:01

Yes I am reading sicp.

Your lack of code tags suggests otherwise.

Name: sage 2008-08-31 12:02

FAIL.

Name: Anonymous 2008-08-31 12:09

I dunno what the fuck you posted but it sure as fuck isn't as beautiful as the Algorithmic Language Scheme that the Sussman taught me as a child.

Name: Sageing fail since 1463 2008-08-31 12:21

fail. Here, a sage.

Name: Anonymous 2008-08-31 12:50

>>1
[[][[]
Where are you going with this, heretic?

Name: Anonymous 2008-08-31 14:23

bampu pantsu

Name: Anonymous 2008-08-31 15:11

>>1
I think you got the normal and applicative orders backwards.

Name: Anonymous 2008-08-31 15:43

>>9
fag

Name: Anonymous 2008-08-31 15:47

I too am reading SICP.
; SICP ex.2.42
; Great Success!
(define (filter predicate items)
  (if (null? items)
      null
      (if (predicate (car items))
          (cons (car items)
                  (filter predicate (cdr items)))
          (filter predicate (cdr items)))))

(define (accumulate op initial sequence)
  (define (iter op sequence partial)
    (if (null? sequence)
        partial
        (iter op
              (cdr sequence)
              (op partial
                  (car sequence)))))
  (iter op sequence initial))

(define (flatmap proc seq)
  (accumulate append null (map proc seq)))

(define (queens board-size)
  (define (queen-cols k)
    (if (= k 0)
        (list empty-board)
        (filter
         (lambda (positions) (safe? k positions))
         (flatmap
          (lambda (rest-of-queens)
            (map (lambda (new-row)
                    (adjoin-position new-row k rest-of-queens))
                  (enumerate-interval 1 board-size)))
        (queen-cols (- k 1))))))
(queen-cols board-size))

(define (enumerate-interval i j)
  (define (iter i j items)
    (if (> i j)
        items
        (iter i (- j 1) (cons j items))))
  (iter i j null))

(define empty-board null)

(define (contains? pred seq)
  (not (null? (find pred seq))))

(define (find pred seq)
  (cond ((null? seq) null)
        ((pred (car seq)) (car seq))
        (else (find pred (cdr seq)))))

(define make-pos cons)
(define col car)
(define row cdr)

(define (checks? queen new-queen)
  (let ((d (- (col new-queen)
              (col queen)))
       (a (row new-queen))
       (b (row queen)))
    (or (= a b) ; check same row
        (= a (- b d)) ; "north-east" diagonal
        (= a (+ b d))))) ; "south-east" diagonal

; given the list of positions of all k queens is the k-th placed in
; a safe position? queens 1 .. k-1 are assumed to be in safe positions
(define (safe? k positions)
  (let ((added (car positions))
        (rest (cdr positions)))
    (not (contains? (lambda (queen) (checks? queen added))
                    rest))))

; add the k-th queen on the position new-row to the rest of the queens
(define (adjoin-position new-row k rest-of-queens)
  (cons (make-pos k new-row) rest-of-queens))

(display (queens 6)) (newline)

Would the Sussman approve my solution dear /prog/?
I have to warn you thou. I write my exercises in VIM.

Name: Anonymous 2008-08-31 16:02

>>7
Apparently he is trying to bring back Superbraces.

Name: Anonymous 2008-08-31 18:48

OP here, is exercise 1.6 a trick question?

'new-if' seems to behave exactly like 'if'.

Name: Anonymous 2008-08-31 19:18

>>13 see >>9

Name: Trollbot9000 2009-07-01 7:55

The empty button to actually move around   as it stops   after just moving   once Heres the   code involved public.

Name: Anonymous 2010-03-23 18:39

I scored 92% on exercise 1.1 !!!!!!!!!!!

Name: Anonymous 2010-03-24 6:08

>>7
It's [b][i][u][o]PLT STYLE[o][/u][/i][/b]

Name: Anonymous 2010-03-24 6:10

>>17
NOOOOOOOOOOOOO

Name: Anonymous 2010-03-24 6:15

>>17
Square brackets aren't PLT specific, they were standardised in R6RS.
http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-7.html#node_sec_4.2.1
<delimiter> → ( | ) | [ | ] | " | ; | #
         | <whitespace>

[Anonymous@/prog/ ~]$ ikarus
Ikarus Scheme version 0.0.4-rc1+ (revision 1870, build 2010-03-23)
Copyright (c) 2006-2009 Abdulaziz Ghuloum

[+ 2 3 4]
9

Name: Anonymous 2010-03-24 6:20

>>19
Oh, and R6RS is dated 26 September 2007

Don't change these.
Name: Email:
Entire Thread Thread List