<tsizz>
aeth: how would i go about returning true or false in an if/else statement
<tsizz>
i was thinking (if (= findf( 200 list) 200) return true else return false
<tsizz>
kind f thing
<aeth>
= is only for numbers.
<aeth>
oh, I see, that is a number it's just syntactically invalid
<aeth>
#t is true and #f is false. But if you're doing (if foo #t #f) you probably don't actually need to do that because foo itself will be fine. (and if you need the opposite just use not)
<tsizz>
aeth: well i want to see if this number in the list
<tsizz>
so i can do findf and return true or false by just putting #t or #f?
<aeth>
If I'm reading the documentation correctly, unless you're searching for the element #f, anything you're returning should be true. And if you use memf, everything you're returning should be true (since it returns a list tail). You don't need it to be #t to be true.
<tsizz>
okay
<tsizz>
but putting #t woudl work anyways?
<tsizz>
and #f
<tsizz>
for false
`micro has joined #racket
<aeth>
Unless Racket adds some weird null/null-like edge cases, everything not #f is true, including #t
<bremner>
that's true in racket, except for certained typed variations (e.g. plait) that are probably not relevant here
<tsizz>
aeth: wait is this cond documentation saying if i want else i have to put it first?
<tsizz>
like (cond else: do this if () do this etc
<aeth>
That's saying that else is one of the valid forms, but the | is an or iirc.
<aeth>
The actual prose says that the else must be the last cond-clause
<tsizz>
aeth: ok so else as last cond-clause?
<tsizz>
last part
notzmv has quit [Ping timeout: 244 seconds]
<aeth>
else must be the last part, if present
<tsizz>
aeth: can i just do (member searchforThis list)
<tsizz>
only problem it doesn't return true, but the tail of list with first element as the found number
<aeth>
I think so, but it would be search-for-this because Lisps use kebab-case
<aeth>
The tail of a list will always be true unless it's the very last part, the terminating '()
`micro has quit [Ping timeout: 246 seconds]
<aeth>
since that doesn't have a first element, that means that the match will always be true
<bremner>
rudybot: (if '() 'true 'false)
<rudybot>
bremner: ; Value: 'true
`micro has joined #racket
<aeth>
oh, right lol
<bremner>
it's a scheme thing, I guess
<aeth>
that always gets me
<aeth>
Although I don't rely on that being false even in Lisps where that is false
<bremner>
elisp things empty lisp is false, iirc
<tsizz>
i think i jsut use boolea not here
<tsizz>
Returns #t if v is #f, #f otherwise.
<aeth>
tsizz: you can say (if (member ...) #t #f) but that's unnecessary because the match is going to be true even if it's not #t so effectively you're substituting some list with #t only to immediately discard the #t
<aeth>
It's possible that the (bytecode?) compiler optimizes that away anyway
<tsizz>
aeth: well im doing cond
<tsizz>
so (cond [(member search-for-this in-this-list)]
<tsizz>
kind of thing
<aeth>
ah, yeah, you can use #t for that
<aeth>
it would go between the ) and the ]. Afaik, []s are interchangable with ()s and they're just used there for clarity
<tsizz>
then if i put [(not(member search-for-this in-this-list))]
<tsizz>
then return #t by putting #t
<aeth>
cond is an if/else-if/else-if/.../else construction.
<tsizz>
its weird but
<tsizz>
well i meant [(not(member search-for-this in-this-list))] as my first if
<aeth>
If you already tested for foo then you don't need to test for (not foo) in the cond because everything in the later clauses are automatically not-foo
<aeth>
ah
<aeth>
yeah, but you want a space between "not" and "("
<aeth>
You also want to give it a return value
<aeth>
In a language with an if/else-if/else-if/.../else block you would create a temporary variable right before that block and set that value in each of the clauses. In cond, you just return a value from each of the clauses and you don't even need that temporary variable at all. That's the power of using expressions for everything.
<tsizz>
aeth: can i do
<tsizz>
(define lis (map ................
<tsizz>
and have lis be what map returns
<tsizz>
the new array
<aeth>
You can but you don't have to unless you're using it more than once.
<aeth>
Using let instead of define for local bindings is more idiomatic imo
keep_learning_M has quit [Quit: This computer has gone to sleep]
<aeth>
(let ((lis (map ...))) ; then the rest of your progran goes here and don't forget to close the let with )
<tsizz>
yeah i realized im first hashing values then have it in a hashList then checking against a dictionary to see if its in the dictionary
<jcowan>
All Lisps have only one falsy object. It's just that in Scheme this is a unique object, whereas in other Lisps, it doubles as the empty list.
<aeth>
If you're making bindings in order you can use let* and it will refer to the previous bindings
<aeth>
(let only lets the binding clauses refer to outer bindings)
<aeth>
It might be clearer to go down a let* in order with each step named instead of composing (foo (bar (baz (quux (quuux ...))))) even though they will be equivalent.
<aeth>
There's probably also a compose macro
keep_learning_M has joined #racket
<tsizz>
now i have to compare this list to dictionary to see if any of numbers in list are in dictionary
<tsizz>
hmmmm
<tsizz>
for-each list and cond in it?
<aeth>
You start with list and you want one result?
<tsizz>
yeah
<tsizz>
reduce ?
<aeth>
remember, you can't have a result in for-each unless you use set!, which you're not allowed to use, because for-each returns nothing
<tsizz>
yeah
<tsizz>
so no for-each
<tsizz>
can i reduce list to like [#t #f #f #f]
<tsizz>
conditional for if numbers in dictionary
<tsizz>
then reduce to #t if there is one or #f
<tsizz>
or else #f*
<aeth>
Well, both. You can go '(a b c d) to '(#t #f #f #F) and then reduce that to #t or #f or you can directly go there, depending on what you want. Ime, the latter is harder, but probably more efficient.
<aeth>
s/#F/#f/
<tsizz>
yeah so that'll be a good place to use reduce right
<tsizz>
how would i change '(a b c d) to '(#t #f ...)...
gnugnugnu has quit [Quit: WeeChat 2.4]
<aeth>
You have two tools that we have been talking about. map and reduce (technically foldl/foldr in racket, but you're using your custom reduce procedure). list->list (where the number of elements match) is map, list->result is reduce.
<aeth>
You should be thinking in terms of substituting one value to another, like in the SICP videos I linked to earlier
<aeth>
It's not a 100% accurate model in practice because there's mutation, but you're not allowed to use set! so it works here.
<aeth>
e.g. (* (+ x y) z) then substitute in the values (* (+ 1 2) 3) then substitute the inner form(s) to (* 3 3) then substitute the next form to 9
<aeth>
(assuming those three variables were bound to 1, 2, and 3 respectively somewhere else in the program)
<aeth>
You can do the same sort of thinking in your program, just with lists instead of only numbers.
<tsizz>
hm okay
<tsizz>
i need to test my teacher's function first
<tsizz>
aeth: doesn't seem to have a reducer or something
<tsizz>
ill brb!
vraid has quit [Ping timeout: 258 seconds]
Fare has quit [Ping timeout: 245 seconds]
efm has quit [Remote host closed the connection]
keep_learning_M has quit [Quit: This computer has gone to sleep]
tsizz_ has joined #racket
<tsizz_>
im back
ZombieChicken has quit [Ping timeout: 256 seconds]
keep_learning_M has joined #racket
tsizz has quit [Ping timeout: 256 seconds]
ZombieChicken has joined #racket
<tsizz_>
aeth: im wondering if this reducer works the same as a normal reducer
<tsizz_>
ok i think it is
<tsizz_>
crap i lost
<tsizz_>
the history of our chart
<tsizz_>
aeth: what was your suggestion again with reduce and member
hjek has quit [Quit: hjek]
hjek has joined #racket
<aeth>
tsizz_: I'm not sure what your question is
jao has joined #racket
<tsizz_>
aeth: i just forgot how u recommended to use reduce
<tsizz_>
i am currently mapping numbers to t/f if they are in the dictionary
<tsizz_>
using map
Diagon has joined #racket
<tsizz_>
aeth: ok i have list (f f f t)
<tsizz_>
how would i reduce to just T
notnotdan[m] has quit [Ping timeout: 256 seconds]
<tsizz_>
aeth: i feel like i dont need a reducer here
notnotdan[m] has joined #racket
<aeth>
tsizz_: you don't need to use reduce, you can just use member, but if you're required to use reduce somewhere and you have not used it, you can use reduce to do the same thing
<aeth>
tsizz_: you can also turn (reduce (map ...)) into one (reduce ...). It will be more complicated, but probably more efficient.
<aeth>
i.e. (reduce b (map a l)) can also just be (reduce a-and-b-in-one-step l)
<tsizz_>
aeth: yeah i didnt want to use reduce for member as it seem counterintuitive and my teacher said use reduce in a useful way
<aeth>
If this helps: map turns l which we can assume is '(a b c d e) into l* which is '(a* b* c* d* e*) and then reduce takes in l* and returns some c. So if you just want to use reduce alone you can just generate a*, b*, etc. in the procedure that reduce is using.
<aeth>
s/some c/some k/
<aeth>
This is because every element of the map is independent of all of the others, assuming that the procedure map takes in is pure (if it's not pure, map could be using some counter variable or whatever, but you can still rewrite it to just use reduce but it could be trickier).
ym555 has quit [Ping timeout: 245 seconds]
ym555 has joined #racket
efm has joined #racket
<tsizz_>
aeth: i am just gonna try reduce on list of (#t #f #t #f ...)
notnotdan[m] has quit [Remote host closed the connection]
<tsizz_>
i think i can make a operator function to do that by just using or boolean
notnotdan[m] has joined #racket
<aeth>
the problem is that or is not a function
<tsizz_>
aeth: wow yeah whaaat
<aeth>
How would you create a function that does the same thing as or for two values (I'm assuming your reduce takes procedures with (x y) as its input)?
<tsizz_>
aeth: well i assume you can just derive or from xor function
<tsizz_>
oh well nvm
<aeth>
there's a simpler solution, think harder
<tsizz_>
if (x = True) else if (y= True) else False
<tsizz_>
if x = true, true, if y = true, true, else false but idk
<aeth>
well, think about it like this... you're comparing two values, so you have a function like this and you just need to fill in the blank: (lambda (x y) ________)
<aeth>
You'd like to use OR but it's a macro on arbitrary values, not a function of two values.
<tsizz_>
so...?
<aeth>
so what's equivalent to (or x y) but in that function body?
efm has quit [Read error: Connection reset by peer]
<tsizz_>
what i wrote before
efm has joined #racket
keep_learning_M has quit [Quit: This computer has gone to sleep]
<aeth>
(if x x (if y y #f)) works but there's a simpler way of writing that, perhaps even a macro that ultimately expands into that as syntactic sugar.
hjek1 has joined #racket
hjek has quit [Read error: Connection reset by peer]
hjek1 is now known as hjek
<s455wang>
tsizz_: for your original questiion of reducing '(#f #f #f #t) to #t, you can use `ormap`
<aeth>
tsizz_: If you're still stumped that's the macro expansion of (or x y) itself or at least very close to it, at least afaik
<aeth>
(if x x (if y y #f)) is roughly equivalent to what you said, which is more directly (if (eq? #t x) #t (if (eq? #t y) #t #f)) because remember anything not #f is true
<aeth>
(and even if you just wanted #t directly, #t's your input, so you still get #t by returning x or y itself)
<tsizz_>
aeth: aw
<tsizz_>
yeah
<tsizz_>
makes sense
<tsizz_>
nice i think i got it!
<tsizz_>
probably bad place to use reduce but idk
<tsizz_>
thinking of other places to use reduce... is there way to reduce a word to do something meaningful
<tsizz_>
idk lol
<aeth>
tsizz_: you probably want to combine the map and the reduce into one reduce now, to make the reduce more meaningful
keep_learning_M has joined #racket
<tsizz_>
aeth: how so?
<tsizz_>
or i mean which map
<aeth>
tsizz_: write a simpler test case with arithemtic, it's always easier with arithmetic imo. e.g. (reduce + (map (lambda (x) (* x 3)) '(1 2 3 4 5)))
keep_learning_M has quit [Client Quit]
dddddd has quit [Remote host closed the connection]
<aeth>
That should be 45. (I tested it with foldl and an initial value of 0 so it's a bit different of an API)
<tsizz_>
wait is this t oflatten the array
keep_learning_M has joined #racket
<aeth>
Notice that I can do (foldl + 0 (map (lambda (x) (* x 3)) '(1 2 3 4 5))) and I can do (foldl (lambda (x y) (+ (* 3 x) y)) 0 '(1 2 3 4 5)) to get the sum of 3*number for all numbers in the list.
hjek has quit [Remote host closed the connection]
hjek has joined #racket
<aeth>
tsizz_: I hope that helps.
keep_learning_M has quit [Quit: This computer has gone to sleep]
amz3 has joined #racket
jao has quit [Ping timeout: 246 seconds]
keep_learning_M has joined #racket
<tsizz_>
aeth: i haven't gotten to it. my thing is broken now D:
Fare has joined #racket
hjek has quit [Quit: hjek]
keep_learning_M has quit [Quit: This computer has gone to sleep]
notzmv has joined #racket
keep_learning_M has joined #racket
ubLIX has quit [Quit: ubLIX]
<tsizz_>
aeth: i wonder if i can reduce with eq?
<tsizz_>
i figured i cant do OR bc all have to be true
Sgeo__ has joined #racket
Sgeo_ has quit [Ping timeout: 268 seconds]
FreeFull has quit []
FareTower has joined #racket
Fare has quit [Quit: Leaving]
FareTower is now known as Fare
ZombieChicken has quit [Ping timeout: 256 seconds]
ZombieChicken has joined #racket
tsizz_ has quit [Quit: Page closed]
orivej has quit [Ping timeout: 240 seconds]
pie___ has joined #racket
pie__ has quit [Ping timeout: 245 seconds]
fructose has joined #racket
lavaflow_ has quit [Read error: Connection reset by peer]
buyfn has joined #racket
buyfn has quit [Client Quit]
ym555 has quit [Ping timeout: 268 seconds]
Fare has quit [Ping timeout: 246 seconds]
keep_learning_M has quit [Quit: This computer has gone to sleep]
keep_learning_M has joined #racket
buyfn has joined #racket
Diagon has quit [Quit: Leaving]
dustyweb has quit [Ping timeout: 252 seconds]
buyfn has quit [Read error: Connection reset by peer]
buyfn has joined #racket
buyfn has quit [Client Quit]
ZombieChicken has quit [Quit: Have a nice day]
ZombieChicken has joined #racket
keep_learning_M has quit [Quit: This computer has gone to sleep]
dustyweb has joined #racket
endformationage has quit [Quit: WeeChat 2.3]
fructose has quit [Quit: Application terminated]
Sgeo_ has joined #racket
Sgeo__ has quit [Ping timeout: 245 seconds]
keep_learning_M has joined #racket
sebastianlin has joined #racket
_whitelogger has joined #racket
buyfn has joined #racket
buyfn has quit [Quit: buyfn]
m1dnight_ has quit [Ping timeout: 264 seconds]
keep_learning_M has quit [Quit: This computer has gone to sleep]
vraid has joined #racket
notzmv has quit [Ping timeout: 246 seconds]
dddddd has joined #racket
forgottenwizard has joined #racket
ZombieChicken has quit [Disconnected by services]
sebastianlin has quit [Ping timeout: 256 seconds]
m1dnight_ has joined #racket
lavaflow_ has joined #racket
ubLIX has joined #racket
sebastianlin has joined #racket
orivej has joined #racket
sebastianlin has quit [Read error: Connection reset by peer]
Sgeo_ has quit [Read error: Connection reset by peer]
Sgeo_ has joined #racket
ym555 has joined #racket
forgottenwizard has quit [Ping timeout: 256 seconds]
YuGiOhJCJ has joined #racket
Fare has joined #racket
acarrico has quit [Ping timeout: 250 seconds]
Arcaelyx has joined #racket
ng0 has joined #racket
acarrico has joined #racket
Arcaelyx has quit [Ping timeout: 246 seconds]
badkins has quit [Remote host closed the connection]
hjek has joined #racket
hjek has quit [Quit: hjek]
hjek has joined #racket
efm has quit [Read error: Connection reset by peer]
hjek has quit [Quit: hjek]
efm has joined #racket
hjek has joined #racket
Fare has quit [Ping timeout: 250 seconds]
efm has quit [Quit: Konversation terminated!]
badkins has joined #racket
Arcaelyx has joined #racket
ym has quit [Remote host closed the connection]
<badkins>
I think the Racket style guide recommends define over let to avoid increasing the indentation level too much. I just discovered a benefit of let (besides not having to repeat "define" ad nauseum) - let will provide a compile time error when referring to a variable that hasn't been defined.
<badkins>
e.g. this compiles w/o error, when I don't think it should: (define (foo) (define b (f2 a)) (define a (f1)) b)
<vraid>
badkins: are you entering that at top-level in the interpreter?
<badkins>
My example was, but the problem was discovered with define's in a main module
endformationage has joined #racket
<badkins>
vraid: just out of curiosity, why do you ask?
<vraid>
ah, i see what the problem is now, i missed the (f2 a) expression
<vraid>
i asked since the top-level lets you retroactively define things
<vraid>
e.g (define (foo) x) is legal even if x is undefined, since you can (define x 5) afterwards, and foo will return that value
<vraid>
in your example, you will have the same issue with (define (foo) (letrec ([b (f2 a)] [a (f1)]) b))
<badkins>
no, that's different
<badkins>
functions vs. variables
<badkins>
both a and b are variables, not functions, so order is important
<badkins>
bottom line, define fails at run time, let fails at compile time
<vraid>
due to the recursive nature of letrec and define
<badkins>
maybe I should've said "values" vs. "functions"
<vraid>
functions are values too
<badkins>
true - I lack the vocabulary :)
<badkins>
vraid: despite my poor description, you can see the problem though, right?
<rain1>
how do i make clickable buttons inside the repl
<vraid>
badkins: yes, sure. i prefer to use let when i can myself. i'm not a racket guru by any means though
badkins has quit [Ping timeout: 245 seconds]
hjek has quit [Quit: hjek]
ym555 has quit [Ping timeout: 245 seconds]
lavaflow_ has quit [Read error: Connection reset by peer]
lavaflow_ has joined #racket
ubLIX has quit [Quit: ubLIX]
jao has joined #racket
badkins has joined #racket
tilpner_ has joined #racket
Arcaelyx_ has joined #racket
ym555 has joined #racket
vraid has quit [Quit: Leaving]
pie___ has quit [Remote host closed the connection]
pie_ has joined #racket
tilpner has quit [Ping timeout: 268 seconds]
pie_ has quit [Remote host closed the connection]
pie_ has joined #racket
Arcaelyx has quit [Ping timeout: 268 seconds]
widp_ has joined #racket
Fare has joined #racket
amz3` has joined #racket
amz3 has quit [Read error: Connection reset by peer]
amz3 has joined #racket
amz3` has quit [Read error: Connection reset by peer]
efm has joined #racket
efm has quit [Ping timeout: 250 seconds]
pera has joined #racket
vraid has joined #racket
selimcan has joined #racket
widp_ has quit [Ping timeout: 240 seconds]
Fare has quit [Ping timeout: 240 seconds]
sauvin has quit [Read error: Connection reset by peer]
_whitelogger has joined #racket
pera has quit [Ping timeout: 255 seconds]
selimcan has quit [Ping timeout: 250 seconds]
<friscosam>
rain1: the DrRacket REPL? You'll probably want to make a snip%