(define (shuffle-planner btn ev)
(define choice (in-entities conn
(~> (from recipe #:as u)
(order-by (["random()"]))
(limit 4))))
(new message%
[parent Today]
[label (recipe-Name (sequence-ref choice 1))]))
Feels like a sort of caching issue that im not “getting” but each time i trigger this function the same choice
is added
where as i would expect that the query would be re-evaluated
is that because its on a different thread ?
Using Deta?
yes
seemed like a nice balance of “simplicity” vs power
Try displaying all four recipe names as a list. Do you still get the same order every time?
Also: Try displaying the resulting query. I am curious whether “random()” turn into a call to random - or whether it is just the string “random()”.
If it just a string, then it explains why the order is the same every time.
@chris613 Try (~> (from recipe #:as u)
(order-by ([(random)]))
(limit 4))))
sorry got distracted … back to this in a tick
ahhh, nope. so i guess the problem is the seq stays about till its flushed :slightly_smiling_face:
thanks
@soegaard2 with a sequence, how would i “take” an item i.e. change my qeuery to have no limit, but then just take an item off the sequence for every call of shuffle-planner
ahhh in-vector ?
or will that convert the whole seq ?
I think that will convert the entire sequence.
I thought there were an sequence-take
but I guess not.
So basically you want to make the query and then process the results one by one?
Maybe use sequence->generator
?
I’ll have a look into that, thanks :)
Something like (define get-choice (sequence->generator (in-entities ...)))
.
Then call (get-choice)
to get one value at a time.
Sweet thanks
I sort of thought a seq was a generator, ootherwise how was it different from a list ;)
More reading needed on my part
I think the term sequence also covers lists, vectors etc.
just before i go a write a bunch of code …. there arent any “binding” libs are there ? to sort of bind a bunch of gui elements to a model ?
or am i fundamentally just thinking the wrong way for racket?
None comes to mind.
coolio thanks :smile:
soooo… in js i might do something like this function make-some-ui() {
...
return {
doThingWithUi(){...},
thing: ....
}
}
i can return a vector of stuff from a function
then somehow destructure that vector into local bindings
is that a common pattern ?
or would the more common thing be to take a name arg and essentially define globals with that name prefix ? like deta does
Just making sure I follow. return {...}
returns an array containing two values: a function named doThingWithUI of no arguments, and some value named thing
?
an annonomus object but yeah same thing for this convo
Is the thing
value an object too?
it was psedo code really, just an example of closing over some stuff and returning a bunch of data & functions and stuff
then the could be used sort later sort of like const {doThingWithUI, thing} = make-some-ui()
doThingWithUI();
Here is something similar in Racket: (struct circle (radius draw))
(define c (circle 10 (lambda () ... draw a circle with radius (circle-radius c) ...)))
((circle-draw c))
That is, you can store “doThing” inside the “thing”.
ahhhh yeah maybe thats what im after
superb thanks :slightly_smiling_face:
A sort-of “poor man’s methods”.
indeed, lightweight objects sort of thing
Often I make a new-circle
function like this
(define (new-circle radius) (define c (circle ...)) c)
That way the user doesn’t need to think of the draw field.
@chris613 You can also use transducers to take the first N elements of a sequence
@chris613 also, if you’re into more list semantics you can check out sequence->stream
since streams are more listy than sequences
Thanks folks! :)