Scheme תרגיל 1

bennyschemeLeave a Comment


תרגיל בית 1 Racket

שאלה  1
 1 א 
> (define apple 'apple)
> (define orange 'orange)
> (define pear 'pear)
> (define grapefruit ' grapefruit)

> (cons apple ( cons orange ( cons pear (cons grapefruit null))))
'(apple orange pear grapefruit)
>
 1 ב 
(list apple orange pear grapefruit)
'(apple orange pear grapefruit)
>

 1 ג
 > '(apple orange pear graperfruit)
'(apple orange pear graperfruit)
>


 2 א 
> (cons(cons apple(cons orange null))(cons(cons pear(cons grapefruit null))null))
'((apple orange) (pear grapefruit))
 2 ב 
> (list (list apple orange) (list pear grapefruit))
'((apple orange) (pear grapefruit))
>



 2 ג
> '((apple orange)(pear grapefruit))
'((apple orange) (pear grapefruit))
>

 3 א 
> (cons(cons(cons apple null) (cons(cons orange null)(cons(cons pear null)(cons(cons grapefruit null)null))))null)
'(((apple) (orange) (pear) (grapefruit)))
 3 ב 
> (list(list(list apple)(list orange)(list pear)(list grapefruit)))
'(((apple) (orange) (pear) (grapefruit)))
 3 ג

> '(((apple)(orange)(pear)(grapefruit)))
'(((apple) (orange) (pear) (grapefruit)))
>

 4 א 
> (cons apple (cons(cons orange null)(cons(cons(cons pear null)null)(cons(cons(cons(cons grapefruit null)null)null)null))))
'(apple (orange) ((pear)) (((grapefruit))))

 4 ב 
> (list apple (list orange) (list(list pear)) (list(list(list grapefruit))))
'(apple (orange) ((pear)) (((grapefruit))))



 4 ג
> '(apple(orange)((pear))(((grapefruit))))
'(apple (orange) ((pear)) (((grapefruit))))

שאלה 2  
נגדיר:
>(define list1 (list apple orange pear grapefruit))     
>(define list2 (list (list apple orange) (list pear grapefruit)))
>(define list3 (list (list (list apple) (list orange) (list pear) (list grapefruit))))
>(define list4 (list apple (list (list orange)) (list (list (list pear))) (list (list (list (list grapefruit))))))


1.	(first (rest (rest list1)))
2.	(first(first(rest list2)))
3.	(first(first(rest(rest(first list3)))))
4.	(first(first(first(first(rest(rest list4))))))
שאלה 3 

1.	(caddr list1)
2.	= (caadr list2)
3.	(car (caddar list3))
4.	(caar (caaddr list4))
שאלה 4
a.	'(a b c)
b.	'((a b c) ())
c.	'((a b c))
d.	'(a b c reverse (a b c) c b a)




שאלה 5
א 
(/(+3 1)(-3 1))
ב   
> ( / ( + 3 1 ) ( - 3 1 ) )
2
שאלה 6 
> (* (max 3 4 5) (min 3 4 5))
15
> (min (max 3 1 4) (max 2 7 1))
4
>







כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *