[racket-users] HTDP2E 22.3 Domain-Specific Languages: Configurations

2020-03-30 Thread Aron Zvi
Hey guys

In 22.3 Domain-Specific Languages: Configurations, the book introduces the 
following data example and data definitions for FSM configurations


(define 

 xm0
  '(machine ((initial "red"))
 (action ((state "red") (next "green")))
 (action ((state "green") (next "yellow")))
 (action ((state "yellow") (next "red")

; An XMachine is a nested list of this shape:
;   `(machine ((initial ,FSM-State 
)) [
List-of 
 
X1T ])
; An X1T is a nested list of this shape:
;   `(action ((state ,FSM-State 
) (
next ,FSM-State 
)))
I do no understand the XMachine data definition properly. In the definition 
it appears that it would be a list with 3 elements:

1*. *'machine
2. `((initial ,FSM-State 
))
3. [List-of 
 
X1T ]

However, from the data example (and the fact that it is an Xexpr 
) I know 
that the intention is different and that it is a list of the form:

1. 'machine
2.  `((initial ,FSM-State 
))
3. X1T -1 
... 
X1T -n

where is seems that [List-of 
 
X1T ]is 
expanded and included in the list  ([List-of 

 X1T ] is 
consed 
onto)

Can you please explain how the given  `(machine ((initial ,FSM-State 
)) [
List-of 
 
X1T ]) 
translates 
to this?





-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/26d8c34b-8ca8-4525-847f-25ba5b6124fa%40googlegroups.com.


[racket-users] HTDP2e Exercise 342 find-all

2020-03-21 Thread Aron Zvi
Hi guys,

Can I get a hint for Exercise 342 find-all
 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/b72826c2-e30a-4e00-96fa-8c968d85d6aa%40googlegroups.com.


[racket-users] Re: HTDP2e part 4: 20.3 Refining Functions dir.rkt

2020-03-19 Thread Aron Zvi
Thanks for your reply Ben.

I understand that I am supposed to be getting a Dir instance.
My confusion is indeed regarding the value of the name field of Dir for 
which I get a (full) path symbol of the directory and not just the folder 
name as I would expect.

When I run (create-dir "test") and the test folder is in the same folder as 
my racket racket file (using just the folder name as you suggested), I get 
the following Dir instance for which the symbol is still the path to the 
folder from the given root

(make-dir
 'test
 (list
  (make-dir
   *'test/a*
   (list (make-dir *'test/a/docs* '() '()))
   (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "") 
(make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""
 (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))

*I am expecting to get this *

(make-dir
 'test
 (list
  (make-dir
   *'a*
   (list (make-dir *'docs* '() '()))
   (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "") 
(make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""
 (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))



On Thursday, 19 March 2020 17:01:59 UTC+7, Aron Zvi wrote:
>
> Hey guys,
>
> In part 4 section 20.3 Refining Functions I am using (require htdp/dir) 
> and (create-dir DIR-PATH). I get back a Dir instance with name value being 
> a full path symbol of the folder. ie. (make-dir 
> '/Users/SSS/Documents/xyz empty empty). 
> This does not seem to be in line with the exercises in the section where 
> it seems that I should be getting back just the folder name.
> I am missing something? 
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/2ba65d76-e548-4fa0-831e-bfce2f9daca7%40googlegroups.com.


[racket-users] HTDP2e part 4: 20.3 Refining Functions dir.rkt

2020-03-19 Thread Aron Zvi
Hey guys,

In part 4 section 20.3 Refining Functions I am using (require htdp/dir) 
and (create-dir DIR-PATH). I get back a Dir instance with name value being 
a full path symbol of the folder. ie. (make-dir 
'/Users/SSS/Documents/xyz empty empty). 
This does not seem to be in line with the exercises in the section where it 
seems that I should be getting back just the folder name.
I am missing something? 




-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/32d5088d-6584-4652-8e62-7a0baa851153%40googlegroups.com.


[racket-users] HTDP2e Exercise 320 help

2020-03-11 Thread Aron-Zvi
Hey guys,

I'm working on Exercise 320 and I am not sure if I am in the right
direction.

For the first part
"Reformulate the data definition for S-expr
 so
that the first clause is expanded into the three clauses of Atom
 and the
second clause uses the List-of

 abstraction"

I get the following Data definition and templates. Is this correct?

; An S-expr is one of:
; – Number
; – String
; – Symbol
; – [List-of S-expr]

(define SEXP0 3)
(define SEXP1 "eff")
(define SEXP2 's)
(define SEXP3 '())
(define SEXP4 (cons 'hello (cons 20.12 (cons "world" '()
(define SEXP5 (cons (cons 'hello (cons 20.12 (cons "world" '(
'()))

#;
(define (fn-for-sexp sexp)
  (cond [(number? sexp) (... sexp)]
[(string? sexp) (... sexp)]
[(symbol? sexp) (... sexp)]
[else
 (... (fn-for-sl sexp))])) ;[List-of S-expr]

#;
(define (fn-for-sl sl)
  (cond [(empty? sl) (...)]
[else
 (... (fn-for-sexp (first sl))   ;S-expr
  (fn-for-sl (rest sl)))]))  ;SL

For the second part
"Now integrate the definition of SL
 into the
one for S-expr
"

I get the following data definition and template. My count function based
of the template works (see third part below) but this looks a bit odd so am
not sure of this

; An S-expr.v2 is one of:
; – Number
; – String
; – Symbol
; – '()
; – (cons S-expr.v2 S-expr.v2)

(define SEXP-V2-0 4)
(define SEXP-V2-1 's)
(define SEXP-V2-2 "ddd")
(define SEXP-V2-3 empty)
(define SEXP-V2-4 '(d kk (3 "4" (1 "gg" f
(define SL0 empty)
(define SL1 '(1 s "d"))
(define SL2 '(1 s (ff 4 ("dd" f)) "d"))

#;
(define (fn-for-sexp.v2 sexp)
  (cond [(number? sexp) (... sexp)]
[(string? sexp) (... sexp)]
[(symbol? sexp) (... sexp)]
[(empty? sexp) (...)]
[else
 (... (first sexp);S-expr.v2
  (rest sexp))])) ;S-expr.v2

and finally the third part
"Simplify count again. Consider using lambda

"

My final count is as below and I do not see how I can simplify more or use
lambda. Can I get a hint?

; S-expr.v2 Symbol -> N
; counts all occurrences of sy in sexp
(check-expect (count.v2 'world 'hello) 0)
(check-expect (count.v2 '(world hello) 'hello) 1)
(check-expect (count.v2 '(((world) hello) hello) 'hello) 2)

;(define (count.v2 sexp sy) 0) ;stub

(define (count.v2 sexp sy)
  (cond [(number? sexp) 0]
[(string? sexp) 0]
[(symbol? sexp) (if (symbol=? sexp sy) 1 0)]
[(empty? sexp) 0]
[else
 (+  (count.v2 (first sexp) sy)
 (count.v2 (rest sexp) sy))]))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CALU5e8LvM63O0TQ8kSt8KJStHdW_ysqdYU2dUHDGuNDshO0dvg%40mail.gmail.com.


Re: [racket-users] HTDP2e Exercise 309

2020-03-05 Thread Aron Zvi
Thanks. I initially tried as below with first pattern [empty empty] and 
empty apparently is a variable that will match a non-empty list. I need to 
use  '*()* 

(define (words-on-line llos)
  (match llos
  [*empty* empty]
  [(list a b ...) ))

On Friday, 6 March 2020 04:01:46 UTC+7, Daniel Prager wrote:
>
> Hint:
>
> (define (words-on-line llos)
>   (match llos
>   ['() empty]
>   [(list a b ...) ))
>
> Dan
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/d8b94ae8-50de-4b66-ac16-7d3225f56b8b%40googlegroups.com.


[racket-users] HTDP2e Exercise 309

2020-03-05 Thread Aron Zvi
Hey Guys,

I do not see how to apply pattern matching to this problem. 
Using for/list as below makes the most sense to me and I do not see how to 
fit in pattern matching

; [List-of [List-of String]] -> [List-of Natural]
; produces list of number of Strings per item in a llos
(check-expect (words-on-line empty) empty)
(check-expect (words-on-line (list empty)) (list 0))
(check-expect (words-on-line (list (list "22" "rr" "ff") (list "22" "rr"))) 
(list 3 2))

(define (words-on-line llos)
  (for/list ((los llos))
(length los)))

Can I get a hint?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/28814482-5ad2-4b8f-9e40-c0b83ffcb30c%40googlegroups.com.


[racket-users] HTDP/2e exercise 219 help

2019-12-01 Thread Aron Zvi
Hey Guys,

I'm having trouble with exercise 219.

I'm following the hint and interpreting “eating” that the head moves where 
the food used to be located. My problem is that I need to the food to be 
(randomly) placed only where the worm head can exactly reach it. 
The worm moves at a fixed increment (speed) and I assume I would need the 
random food to be at a position divisible by the worm's speed. However, the 
functions provided for food creation in figure 80 will generate a a 
standard random position and I am left with food that my worm cannot eat

You help is mostly appreciated


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/6fef35e4-09a0-4e3b-8c39-5d3dc20c37b0%40googlegroups.com.


[racket-users] HTDP/2e help

2019-11-18 Thread Aron Zvi
Hi guys,

I am working through HTDP/2e alone and I occasionaly have trouble with the 
exercises. Is this the right place to ask for help? If so, what is the proper 
way to ask?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/73bac84f-4e75-45cb-873d-c6a0c43874fc%40googlegroups.com.