chris613
2020-1-16 10:35:35

(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


chris613
2020-1-16 10:36:03

where as i would expect that the query would be re-evaluated


chris613
2020-1-16 10:36:22

is that because its on a different thread ?


soegaard2
2020-1-16 10:38:08

Using Deta?


chris613
2020-1-16 10:38:30

yes


chris613
2020-1-16 10:38:50

seemed like a nice balance of “simplicity” vs power


soegaard2
2020-1-16 10:39:39

Try displaying all four recipe names as a list. Do you still get the same order every time?


soegaard2
2020-1-16 10:41:41

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()”.


soegaard2
2020-1-16 10:41:57

If it just a string, then it explains why the order is the same every time.


soegaard2
2020-1-16 10:58:55

@chris613 Try (~> (from recipe #:as u) (order-by ([(random)])) (limit 4))))


chris613
2020-1-16 11:06:25

sorry got distracted … back to this in a tick


chris613
2020-1-16 11:07:21

ahhh, nope. so i guess the problem is the seq stays about till its flushed :slightly_smiling_face:


chris613
2020-1-16 11:07:23

thanks


chris613
2020-1-16 12:31:24

@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


chris613
2020-1-16 12:35:01

ahhh in-vector ?


chris613
2020-1-16 12:35:11

or will that convert the whole seq ?


soegaard2
2020-1-16 12:35:28

I think that will convert the entire sequence.


soegaard2
2020-1-16 12:35:58

I thought there were an sequence-take but I guess not.


soegaard2
2020-1-16 12:36:28

So basically you want to make the query and then process the results one by one?


soegaard2
2020-1-16 12:38:18

Maybe use sequence->generator ?


chris613
2020-1-16 12:38:46

I’ll have a look into that, thanks :)


soegaard2
2020-1-16 12:39:13

Something like (define get-choice (sequence->generator (in-entities ...))).


soegaard2
2020-1-16 12:39:32

Then call (get-choice) to get one value at a time.


chris613
2020-1-16 12:39:53

Sweet thanks


chris613
2020-1-16 12:40:24

I sort of thought a seq was a generator, ootherwise how was it different from a list ;)


chris613
2020-1-16 12:40:33

More reading needed on my part


soegaard2
2020-1-16 12:41:44

I think the term sequence also covers lists, vectors etc.


chris613
2020-1-16 14:20:25

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 ?


chris613
2020-1-16 14:20:38

or am i fundamentally just thinking the wrong way for racket?


soegaard2
2020-1-16 14:21:53

None comes to mind.


chris613
2020-1-16 14:24:05

coolio thanks :smile:


chris613
2020-1-16 14:29:11

soooo… in js i might do something like this function make-some-ui() { ... return { doThingWithUi(){...}, thing: .... } }


chris613
2020-1-16 14:30:17

i can return a vector of stuff from a function


chris613
2020-1-16 14:30:43

then somehow destructure that vector into local bindings


chris613
2020-1-16 14:30:48

is that a common pattern ?


chris613
2020-1-16 14:31:57

or would the more common thing be to take a name arg and essentially define globals with that name prefix ? like deta does


soegaard2
2020-1-16 14:33:21

Just making sure I follow. return {...} returns an array containing two values: a function named doThingWithUI of no arguments, and some value named thing ?


chris613
2020-1-16 14:33:50

an annonomus object but yeah same thing for this convo


soegaard2
2020-1-16 14:34:31

Is the thing value an object too?


chris613
2020-1-16 14:34:40

it was psedo code really, just an example of closing over some stuff and returning a bunch of data & functions and stuff


chris613
2020-1-16 14:35:33

then the could be used sort later sort of like const {doThingWithUI, thing} = make-some-ui() doThingWithUI();


soegaard2
2020-1-16 14:38:14

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))


soegaard2
2020-1-16 14:38:39

That is, you can store “doThing” inside the “thing”.


chris613
2020-1-16 14:39:00

ahhhh yeah maybe thats what im after


chris613
2020-1-16 14:39:03

superb thanks :slightly_smiling_face:


soegaard2
2020-1-16 14:39:14

A sort-of “poor man’s methods”.


chris613
2020-1-16 14:39:30

indeed, lightweight objects sort of thing


soegaard2
2020-1-16 14:40:19

Often I make a new-circle function like this


soegaard2
2020-1-16 14:40:42

(define (new-circle radius) (define c (circle ...)) c)


soegaard2
2020-1-16 14:41:15

That way the user doesn’t need to think of the draw field.


notjack
2020-1-16 18:17:32

@chris613 You can also use transducers to take the first N elements of a sequence


samdphillips
2020-1-16 18:30:46

@chris613 also, if you’re into more list semantics you can check out sequence->streamsince streams are more listy than sequences


chris613
2020-1-16 19:53:19

Thanks folks! :)