Page 1 of 1

### Help for the first program of a newbie

Posted: 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?' ?
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 !

### Re: Help for the first program of a newbie

Posted: 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.