Help for the first program of a newbie

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

Help for the first program of a newbie

Postby MrLouis » Sun Feb 28, 2016 7:45 am

Hello,
(I hope is the good section?!)
I begin the scheme and I try to do a small MasterMind. But I can't structure correctly the programm and I'm not sure to understand the indent style and how use and change the variables.
I don't understand too what is the different between 'and' and 'and?' :idea: ?
And why 'not' is not 'not?' ;) , they are twice predicates, no ?

Code: Select all
#lang racket
;; Master Mind ;;
(define nC 8)
(define lType [list nC nC nC nC])
(define nMyst (map (lambda (n) (random n)) lType))
(define (ask)
   (let* ([i (read [current-input-port])])
     (if (and (integer? i)
              (>= i 0)
              (< i nC)) i (begin [printf "You must write a number between 0 and ~a\n" (- nC 1)]
                                 ask))
    )
   )
(define (L L1)
  (let* ([ans (list (ask) (ask) (ask) (ask))])
    (list
     (map [lambda (a b) (if (equal? a b) 'T [if [ormap equal? (list a a a a) L1] 'B 'F])] ans L1)
     ans)
    )
  )
(do ([nT 0 (+ nT 1)]
     [iList (L nMyst) (append (L nMyst) iList)])
  ((equal? (second iList) nMyst) (printf "You win: ~a !!" nMyst))
  (begin
    (printf "Round n°~a, \nF => False \nB => Bad Position \nT => True \nIt is incorrect: \n" nT)
    (for-each (lambda (arg) (printf "~a\n" arg)) iList)
    )
  )


Thanks for your future help !
MrLouis
 
Posts: 1
Joined: Sun Feb 28, 2016 7:09 am

Re: Help for the first program of a newbie

Postby Goheeca » Thu Mar 03, 2016 10:48 am

Here is a good article for the indentation of Common Lisp, that should be fine for scheme/racket too.
Changing variables is done through set! (the exclamation mark denotes that the function has side effects):
Code: Select all
(define x 0)
(set! x 1)

What concerns the pairs and/and? and not/not?, without question marks they are just building blocks of boolean expressions, whereas with question marks they combines predicate functions and returns a combined predicate function.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
User avatar
Goheeca
 
Posts: 271
Joined: Thu May 10, 2012 12:54 pm


Return to Homework

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron