@ma77rix go ahead. Everyone else is on the other side of planet earth, therefore sleeping. :slightly_smiling_face:
How can I specify #:methods
on structure types created with make-struct-type
? Surely this is possible but the docs on make-struct-type
doesn’t even refer to #:methods
.
Is there maybe a correspondence between methods and properties that I can advantage of and maybe specify methods as properties?
I don’t think there’s currently a supported way to do that
really? that’s really strange.
I was just reading racket code to understand how deep the rabbit hole goes.
This line here
seems to be where #:methods
are handled.
somehow this seems to convert methods into properties.
Unfortunately though, the operations used to do this are not exported, like generic-property
.
What this seems to mean is that there’s no way to implement struct-types at runtime which implement a set of generic methods, which would be quite a serious shortcoming for someone who really needs these things. me
I think struct
definitions work at runtime too
#:methods
is internally implemented using struct properties and the APIs here https://github.com/racket/racket/blob/master/racket/collects/racket/private/generic-methods.rkt
but I think struct properties is all what make-struct-type
knows
@shu—hung ok, I am actually quite surprised that you are right. i was quite sure this was not going to work: (define (make-s) (struct foo (a b) #:mutable #:extra-constructor-name make-foo) make-foo)
but it did.
yeah struct
expands to call to make-struct-type
at runtime
is there any way to make this: (assq 'select '((SELECT . "dummy") (DROP . "hat")))
return the first pair - to make the comparison case insensitive?
@githree maybe use assf
and a comparison function?
I tried this: (assf (lambda (arg) (eq? 'select #ci arg)) '((SELECT . "dummy") (DROP . "hat")))
but no success
I could do symbol->string
and then use string-ci=?
but was wondering if there was more elegant solution
@githree that’s what I would do
ok, thanks
thanks, I found this common lisp doc http://www.lispworks.com/documentation/HyperSpec/Body/m_do_do.htm with more examples which is helpful, but Im not sure that it works in racket, is there any doc about comparing racket and common lisp ?
another question is I’m still not clear about continuation and lambda, could you guys pls recommend some good article/book about them ?
Common Lisp and Racket have a common ancestor about 40 years ago, so taking code from one to the other isn’t going to be very helpful
I found racket do doc first, but it doesn’t explain var in do loop https://docs.racket-lang.org/reference/for.html
those are both big topics — I would recommend books like “The Little Schemer”, “How to Design Programs”, or others
i see, thanks :+1:
Racket programmers don’t usually use do
at all
you mean we should use recursion instead of do
?
just start learning racket
I would use for
and other related loop constructs
if you’re new to racket, I recommend the “Realm of Racket” book as well
will go check it. thanks :slightly_smiling_face:
I like that xrepl is enabled by default these days, but. How can I temporarily disable it? (I want to experiment with racket -it program-using-datalog.rkt
, and rule out xrepl contributing to the problem.)
Oh -q
seems to do the trick.
@greg for more info, see the docs for racket/interactive
http://docs.racket-lang.org/reference/running-sa.html#%28mod-path._racket%2Finteractive%29
Thanks, that is indeed where I found -q
just now. :slightly_smiling_face:
Hello, I know the meaning of each expression, but don’t understand why we need values
in the for
loop ? (for/fold ([sqrs 0]
[count 0])
([i '(1 2 3 4 5 6 7 8 9 10)])
(values (+ (sqr i) sqrs)
(if (> (sqr i) 50)
(add1 count)
count)))
@ma77rix You need values in the for loop because you are folding over 2 values.
No values are needed if folding over a single value.
You are folding over sqrs
and count
.
To add all the elements of a list with for/fold
: (for ([accum 0]) ([i (in-range 10)]) (+ accum i))
No values
needed as you are accumulating a single value.
Thanks Paulo. I got it, but why ? why we need values
when for/fold
more than one value ?
My Racket app spawns another process. What’s the best way to ensure no matter what happens, that process gets cleaned up? I looked around at custodians, but it doesn’t seem quite right. Neither do some searches for finalizers.
Any suggestions?
@ma77rix what would the alternative be? You need to state the values to use in the next loop iteration.
@jboyens are these threads or places or subprocesses?