[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Learning Racket from the Racket Guide. What's the deal with

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 67
Thread images: 11

File: unsolvable.jpg (66KB, 689x687px) Image search: [Google]
unsolvable.jpg
66KB, 689x687px
Learning Racket from the Racket Guide.
What's the deal with symbols and identifiers.

Can somebody explain to me interning, uninterning, and quoting symbols
also, dot notation in lists

super confused!

>pic unrelated
>>
>>57758021
oh yeah, and also, keywords
>>
>>57758021
You integrate (10sinX/2X)dx ,lower limit 12
>>
>>57758346
Wrong!
>>
>>57758346
5pi/2
>>
>>57758346
>>57758400
Both Wrong!
>>
>>57758021
complex analysis helps
>>
>>57758021
5pi/sqrt(2)
>>
>>57758624
Correct!
>>
>>57758021
Obviously fucking zero
>>
that's an improper integral right?
>>
This is all related to the reader, which turns streams of characters (the text files you write) into racket objects that racket can compile/evaluate.

Most symbols are "interned" symbols, which means they're eq? (the same object) when their names are the same string.
This is not the case with "uninterned" symbols. One uninterned symbol named "sym" is a different object from another uninterned symbol named "sym". That is, (eq? (string->uninterned-symbol "sym") (string->uninterned-symbol "sym")) is always #f, for any possible symbol name.

In racket, once a value is read in by "read", it is then passed to the evaluator to produce a value. Quotation stops the evaluation step, giving you the value read by the reader.

For example, when you type "(+ 1 2)" at the REPL, the reader reads in the list "(+ 1 2)", then passes that to the evaluator, producing the number "3". If you quote the expression instead, the evaluation step is skipped, and you just get back the list that was read in. Thus, " '(+ 1 2)" yields the list "(+ 1 2)". Similarly, " 'var" returns the symbol " 'var", and not the value which is bound to var.

Dot-notation is a way of writing a literal cons. That is, "(cons 1 2)" produces a pair, which is printed as " '(1 . 2)". You can also provide " '(1 . 2)" as input to get back a value-equal cons object of " '(1 . 2)".

Keywords are like interned symbols, but you can't bind values to them and they aren't valid expressions on their own (though you can still quote them, e.g. " '#:keyword" is a valid expression). They're mainly used to provide named arguments to functions.

I'm not a racket expert, so the above is true to the best of my knowledge. I apologize if I got anything wrong.
>>
>>57759817
Yes between Infinity and zero,

>>57758624
>>57758664
Is it sqrt2 or 2^2?
>>
At first look it doesn't look like it converges tbqh
>>
>>57759853
not them but p sure it's meant to be 2^2 not sqrt2
>>
>sqrt(2)
wrong

it's 5pi/2
>>
>>57760039
use your brain, if they wanted 2glass, then it would've been like the others
notice how its not 3 beers together, but three beers added, which means them want 3beer, not beer^3
>>
>>57759838
I see, thanks!
Also,
what does
(1 . < . 2) and (1 2 . 3) mean
>>
>>57760296
The standard list notation is short for nested cons. That is, (1 2 3) is short for (cons 1 (cons 2 (cons 3 '()))). You could also write this as '(1 . (2 . (3 . ())))

Such a list is called a "proper list". A list where the final CDR is not the empty list is called an " improper list". It can be written as a literal by putting a dot before the final CDR. Thus, (cons 1 (cons 2 3)) is '(1 2 . 3). Also, '(1 2 3) is '(1 2 3 . ()).
>>
File: SIMPLER.jpg (214KB, 925x731px) Image search: [Google]
SIMPLER.jpg
214KB, 925x731px
>>
File: images.jpg (18KB, 225x225px) Image search: [Google]
images.jpg
18KB, 225x225px
>>57761999
This gave me a panic attack
>>
>>57759853
I thought it could be from any number to infinity. Doesn't it depend on the domain
>>
File: Screenshot_20161129-222704.png (215KB, 2560x1440px) Image search: [Google]
Screenshot_20161129-222704.png
215KB, 2560x1440px
>>57758393
>>57758433
I challenge you to deny this
>>
>>57762186
your constants are wrong
>>
>>57762186
>he uses wolfram alpha to solve problems
>>>/fizzbuzz general/
>>
>>57760296
(x . f . y) is special racket syntax that is exactly the same as (f x y)
Basically if you have two dots in a list, then if takes the thing between the dots and moves it to the beginning
>>
>>57762475
thanks for you help!
>>
>>57762172
Are you mixing up domain and range? Am I? I do all the time.
>>
>>57762475
and it works whereever it is, not matter how much inputs?

(+ '(1 2 3 4) '(3 2 1 0) . map .)
>>
>>57762688
The lovely thing about Racket (and many other languages) is that it's very easy to test it out for yourself :)
$ racket
Welcome to Racket v6.7.
> '(b c . a .)
; readline-input:1:6: read: illegal use of `)' [,bt for context]
> '(. a . b c)
; readline-input:2:2: read: illegal use of `.' [,bt for context]
; a: undefined;
; cannot reference undefined identifier
; [,bt for context]
; readline-input:2:6: read: illegal use of `.' [,bt for context]
; b: undefined;
; cannot reference undefined identifier
; [,bt for context]
; c: undefined;
; cannot reference undefined identifier
; [,bt for context]
; readline-input:2:11: read: unexpected `)' [,bt for context]
> '(b c . a . d e)
'(a b c d e)


The two-dots syntax (infix syntax) is especially useful for the -> and ->* contracts, used for constructing a kind of runtime "type system". Speficially, it can be more clear to use
(input? . -> . output?)

than
(-> input? output?)

https://docs.racket-lang.org/reference/function-contracts.html#(form._((lib._racket%2Fcontract%2Fbase..rkt)._-~3e))
; thing.rkt
#lang racket
(provide
(contract-out
[thing (integer? . -> . integer?)]))

(define (thing x) (+ (* 2 x) 1))

; main.rkt
#lang racket
(require "thing.rkt")
(displayln (thing 4)) ; 9
(displayln (thing 4.5)) ; ERROR...
>>
>>57762688
I believe the dots will work anywhere except the beginning or the end, since it's mostly meant for stuff like '>', where it makes more sense to see it in order. Most of the stuff this notation is useful for is stuff that's basic syntax in other languages, and you don't always think of as a function.

Something like map is a normal function, so it makes sense to leave it at the beginning.
>>
>>57762818
did you learn from the guide or did you read one of the books?
>>
>>57763026
I knew a bit of scheme (and other langauges) before I learned Racket, and I learned from making programs in Racket and subsequently reading through the docs alot :-/
I love the language, I think its fantastic
>>
>>57763117
I'm going to do PLAI.
also, any big programs you've made?
>>
>>57763142
>also, any big programs you've made?
Yes!
I'm making my personal website completely in Racket.
https://justiota[dot]tk/
The source is a little bit of a cluster fuck I guess, and I tend to use the quite heavy (match ...) and (for ...) macros a lot... https://gitla.in/iitalics/xi/blob/master/xi/xexpr.rkt is pretty simple if you want to have a look.
This converts "x-expressions" into HTML code, for instance.
(xexpr
`(span "Click "
(a #:href "there" "here!")))

Becomes
<span>Click <a href="there">here!</a></span>
>>
>>57763258
you wrote the backend and frontend?
>>
File: autism.png (495KB, 1112x1315px) Image search: [Google]
autism.png
495KB, 1112x1315px
>>57762405
Not him but I'm pretty sure that's the right answer
>>
>>57763311
Yes. xi handles HTTP requests and provides a simple interface for providing responses. I'm still working on some features (for instance, query support is pretty weak)
Example website using it:
(require
xi/common
xi/http-utils)

(define-route '(/)
(λ (req)
(res/html
`(html
(body (h1 "Hello world")
(a #:href "/more"
"More stuff"))))))

(define-route '(/ more)
(λ (req)
(res/html
`(html
(body (h2 "TODO: add stuff"))))))

(define-route 404
(λ (req)
(res/html
`(html
(body (h1 "Nothing here"))))))

(start-server 8080)
>>
File: tmp_25874-5PieOver21856601842.jpg (94KB, 819x675px) Image search: [Google]
tmp_25874-5PieOver21856601842.jpg
94KB, 819x675px
>>57763375
You're wrong. Pic related is obviously the correct answer.
>>
>>57759838
keywords generally evaluate to themselves. Everything is a valid expression in Lisp (barring syntax errors), that's the point.
>>
>>57763858
heh
>>
>>57758433
Start giving the correct answer with proof
>>
>>57763883
Keywords evaluate to themselves in Common Lisp, and possibly other lisps, but not in racket. See http://docs.racket-lang.org/guide/keywords.html
>>
>>57764592
That would leave me as a joke.
I can't jeopardize my reputation in an anonymous key-chain adornment forum.
>>
>unsolvable.jpg
op pls
3 0 0 | 30
1 2 0 | 20
0 1 4 | 9
row-reduce, yielding:
1 0 0 | 10
0 1 0 | 5
0 0 1 | 1

integrate from (5 + 5 - 10 = 0) to infinity, (10*sin(h))/(2h)dh

simplify to 5*integral(sin(h)/h, h), yielding 5*pi/2
>>
>>57764721
Whoops, shit, I meant (10*sin(h))/(1h)dh, which eventually leads us to 5*pi.
>>
File: 1386928569388.jpg (26KB, 300x300px) Image search: [Google]
1386928569388.jpg
26KB, 300x300px
>>57758021
I've basically completely forgotten high-school calculus.
>>
>>57764758
>highschool
this is college calculus
>>
>>57764616
That's horrifying. Why destroy Lisp's purity for the purpose of, what?, preventing people from abusing keyword evaluation? That means that function calls do not evaluate all of their arguments, because keywords are not expressions that can be evaluated.
>>
>>57765084
Not hom but back in the time that was high-school calculus
>>
>>57765147
Keyword arguments to functions were always special.
>>
>>57765247
No, if keywords evaluated to themselves you do not need special handling of the function call.

Handling of the keyword arguments can be built into the defun/lambda macro, but there's no need to gut the semantics of list evaluation.
>>
>>57765084
>Simple integration
>College calculus
Is the American education system really that shit?
>>
>>57758021
>bottle = 10
>hamburger = 5
>beer = 2

Move the constant out, integral becomes 5·integrate[x, 0, infty, sinc(x)]

This becomes 5 · lim (x->infty) Si(x), which converges towards 5 · pi/2 or 2.5π.
>>
>>57758021
I don't remember if Racket has proper meta-programming facilities like macros, quasiquoting, etc... (since there are several typed and untyped variants included with DrRacket) but in general, symbols and identifiers are likely represented internally as thunks using continuation passing style. If that answers your question.
>>
>>57765460
this, everyone else is wrong
>>
>>57765370
>simple integration
the proof of x->infinity Si(x) = pi/2 is very nontrivial and canonically involves complex analysis and contour integrals
>>
>>57759889
It's a sinc function, of course it converges.
>>
File: raetsel.jpg (50KB, 1275x683px) Image search: [Google]
raetsel.jpg
50KB, 1275x683px
I enjoy putting Nic Cage in there for good measure.
>>
File: 2016-11-30 14-33-44.png (19KB, 376x250px) Image search: [Google]
2016-11-30 14-33-44.png
19KB, 376x250px
>>57762186
The pleasure is all mine
>>
>>57767830
Pint instead of beer under the fraction you fucking idiot.
>>
File: 2016-11-30 14-39-25.png (20KB, 398x252px) Image search: [Google]
2016-11-30 14-39-25.png
20KB, 398x252px
>>57767842
Whoopsie
>>
>>57758021
it's not solvable. it does not tell you if it is sin degrees or rad.
>>
File: lol.png (87KB, 1280x800px) Image search: [Google]
lol.png
87KB, 1280x800px
>>57758021
Mathematica sure is nice
>>
>>57767934
>it's not solvable. it does not tell you if it is sin degrees or rad.

sin is always in radians.

If you want to use degrees, you must define a different function, for example;

sindeg(x) = sin(180x/π)

or else use a composition of functions:

sin(degtorad(x))
>>
>>57767969
what application is this ?
>>
>>57768768
Probably this https://www.wolfram.com/mathematica/
Thread posts: 67
Thread images: 11


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.