blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
171
content_id
stringlengths
40
40
detected_licenses
listlengths
0
8
license_type
stringclasses
2 values
repo_name
stringlengths
6
82
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
13 values
visit_date
timestamp[ns]
revision_date
timestamp[ns]
committer_date
timestamp[ns]
github_id
int64
1.59k
594M
star_events_count
int64
0
77.1k
fork_events_count
int64
0
33.7k
gha_license_id
stringclasses
12 values
gha_event_created_at
timestamp[ns]
gha_created_at
timestamp[ns]
gha_language
stringclasses
46 values
src_encoding
stringclasses
14 values
language
stringclasses
2 values
is_vendor
bool
2 classes
is_generated
bool
1 class
length_bytes
int64
4
7.87M
extension
stringclasses
101 values
filename
stringlengths
2
149
content
stringlengths
4
7.87M
has_macro_def
bool
2 classes
28f18db21994afa6f4c53e2143009f71057ef5ae
6e2088c94931e0baea8e834203d3ccb478828335
/remora/scribblings/tutorial.scrbl
ff1c98f7c88bd10edfd65f37499be8e2b7033908
[]
no_license
jrslepak/Remora
d5155a78b5c952a822ce65109d092bd6a27545ec
1a831dec554df9a7ef3eeb10f0d22036f1f86dbd
refs/heads/master
2020-04-05T14:35:48.257381
2020-03-24T18:18:34
2020-03-24T18:18:34
10,669,532
119
12
null
2016-09-02T13:48:11
2013-06-13T15:41:04
Racket
UTF-8
Racket
false
false
17,445
scrbl
tutorial.scrbl
#lang scribble/manual @require[scribble/eval scribble/core racket/sandbox remora/dynamic/lang/reader (for-label remora/dynamic (only-in remora/dynamic/lang/language define λ))] @title[#:version "" #:date ""]{Remora Tutorial} @(sandbox-output 'string) @(define example-evaluator (parameterize ([sandbox-output 'string] [sandbox-error-output 'string]) (make-evaluator 'remora/dynamic/lang/language))) @;{TODO: using #:lang option with `code' keeps hyperlinks from generating} Much of Remora is not too different from other functional languages. @;{ @interaction[#:eval example-evaluator (+ 1 3) ((compose sqrt add1) 3) ] @interaction-eval-show[#:eval example-evaluator (+ 2 6)] } @nested[#:style 'code-inset]{ @racketinput0[(+ 1 3)] @racket[#,(racketresultfont (tt "4"))]} @nested[#:style 'code-inset]{ @racketinput0[((compose sqrt add1) 3)] @racket[#,(racketresultfont (tt "2"))]} @nested[#:style 'code-inset]{ @racketinput0[(foldr + 0 [0 1 2 3])] @racket[#,(racketresultfont (tt "6"))]} Wait, something is a little different there. @code[#:lang "remora/dynamic"]{[0 1 2 3]} is an array, not a list. It's made of four ``@deftech{atoms},'' laid out in a row of length four. We could write out this structure more explicitly as: @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic #A(4)(0 1 2 3) } Instead of a single row of four, we could have two rows of two: @tabular[#:sep @hspace[3] (list (append (list @codeblock[#:keep-lang-line? #f]{#lang remora/dynamic [[0 1] [2 3]]}) (list "or" @hspace[2]) (list @codeblock[#:keep-lang-line? #f]{#lang remora/dynamic #A(2 2)(0 1 2 3)})))] But what we had before wasn't really @emph{one} row of four. It doesn't have any rows, just the four atoms. One row of four would be @tabular[#:sep @hspace[3] (list (append (list @codeblock[#:keep-lang-line? #f]{#lang remora/dynamic [[0 1 2 3]]}) (list "or" @hspace[2]) (list @codeblock[#:keep-lang-line? #f]{#lang remora/dynamic #A(1 4)(0 1 2 3)})))] This is like the difference between a line and a narrow rectangle. A rectangle has a length and a width, while a line has just a length. The line doesn't have a very small width --- it has no width at all. The line extends along just one @deftech[#:normalize? #f]{axis}, and the rectangle extends along two axes. How many axes an array has is called its @deftech{rank}. The @deftech{shape} of an array is how far it extends along each axis. @code[#:lang "remora/dynamic"]{[0 1 2 3]}, or @code[#:lang "remora/dynamic"]{#A(4)(0 1 2 3)}, is a @tech{rank}-1 array with shape @code[#:lang "remora/dynamic"]{[4]}. @code[#:lang "remora/dynamic"]{[[0 1] [2 3]]}, or @code[#:lang "remora/dynamic"]{#A(2 2)(0 1 2 3)}, is a @tech{rank}-2 array with shape @code[#:lang "remora/dynamic"]{[2 2]}. Actually, we've been working with arrays since the beginning: @racketblock[(+ 1 3)] These three things are @tech{rank}-0 arrays --- each one has shape @code[#:lang "remora/dynamic"]{[]}. ``@racket[+]'' is the name of an array whose only atom is the addition function. @racket[1] in the above expression doesn't really stand for the number one, but this @racket[1] does: @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic #A()(1) } That notation is an @deftech{array literal}. It gets some numbers to describe the shape and some atoms. We cannot have @code[#:lang "remora/dynamic"]{#A()((+ 1 3))} because @code[#:lang "remora/dynamic"]{(+ 1 3)} is not an atom (it is an expression). Inside an array literal is the only place we talk about atoms. Even in @code[#:lang "remora/dynamic"]{[0 1 2 3]}, these are expressions. This means @code[#:lang "remora/dynamic"]{[(+ 1 3)]} is allowed --- it produces @code[#:lang "remora/dynamic"]{[4]}, or @code[#:lang "remora/dynamic"]{#A()(4)}. If the pieces of @code[#:lang "remora/dynamic"]{(+ 1 3)} are arrays, what happens when we use different arrays? @racketinput[(+ [10 20 30] 3)] @racketblock[#,(racketresultfont (tt "[13 23 33]"))] Function application in Remora does a bit more than we saw before. Addition and 3 were repeated with each of 10, 20, and 30, as if we'd written @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic [(+ 10 3) (+ 20 3) (+ 30 3)] } We'd get the same result from @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic ([+ + +] [10 20 30] [3 3 3]) } In that version, there's some similarity the arrays' shapes all share. Each is a @deftech{frame} of @code[#:lang "remora/dynamic"]{[3]} built around the fundamental unit we're computing on. We call those units @deftech{cells}. In our vector-and-scalars expression, @code[#:lang "remora/dynamic"]{(+ [10 20 30] 3)}, the @tech{frames} are @code[#:lang "remora/dynamic"]{[]}, @code[#:lang "remora/dynamic"]{[3]}, and @code[#:lang "remora/dynamic"]{[]}. They're not all the same, but they're close enough: We can add extra @tech[#:key "axis" #:normalize? #f]{axes} at the right ends of lower-@tech{rank}ed @tech{frames} in order to make them the same as the highest-@tech{rank}ed @tech{frame}. Adding more axes to an array means its @tech{cells} get replicated too: @code[#:lang "remora/dynamic"]{+} becomes @code[#:lang "remora/dynamic"]{[+ + +]}, and @code[#:lang "remora/dynamic"]{3} becomes @code[#:lang "remora/dynamic"]{[3 3 3]}. Let's try higher-@tech{rank} arrays: @nested[#:style 'code-inset]{ @racketinput0[(+ [[1 2 3] [4 5 6]] [10 20])] @racket[#,(racketresultfont (tt "[[11 12 13] [24 25 26]]"))]} Now, the @tech{frames} are @code[#:lang "remora/dynamic"]{[]}, @code[#:lang "remora/dynamic"]{[2 3]}, and @code[#:lang "remora/dynamic"]{[2]}. That means the shape of @code[#:lang "remora/dynamic"]{+} needs to be extended with @code[#:lang "remora/dynamic"]{[2 3]}, and the shape of @code[#:lang "remora/dynamic"]{[10 20]} needs to be exteneded with @code[#:lang "remora/dynamic"]{[3]}. @code[#:lang "remora/dynamic"]{+} has only one @tech{cell}, so we make 2 × 3 = 6 copies of it: @code[#:lang "remora/dynamic"]{[[+ + +] [+ + +]]}. @code[#:lang "remora/dynamic"]{[10 20]} has two @tech{cells}, @code[#:lang "remora/dynamic"]{10} and @code[#:lang "remora/dynamic"]{20}. We make 3 copies of each: @code[#:lang "remora/dynamic"]{[[10 10 10] [20 20 20]]}. So the matrix-vector addition is the same as the all-matrix expressions @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic ([[+ + +] [+ + +]] [[1 2 3] [4 5 6]] [[10 10 10] [20 20 20]]) } and @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic [[(+ 1 10) (+ 2 10) (+ 3 10)] [(+ 4 20) (+ 5 20) (+ 6 20)]] } We effectively treated @code[#:lang "remora/dynamic"]{[10 20]} as a column by adding another @tech[#:normalize? #f]{axis} to its shape after the @code[#:lang "remora/dynamic"]{2}. Not all operations behave like @code[#:lang "remora/dynamic"]{+} in this regard. The @code[#:lang "remora/dynamic"]{base} operator interprets a vector of digits according to a given radix vector. @nested[#:style 'code-inset]{ @racketinput0[(base [8 8] [3 1])] @racket[#,(racketresultfont (tt "25"))]} In octal, the digits @code[#:lang "remora/dynamic"]{[3 1]} represent the decimal number @code[#:lang "remora/dynamic"]{25}. The fundamental unit in each of @code[#:lang "remora/dynamic"]{base}'s arguments is a vector, a @tech{rank}-1 array. So we say that @code[#:lang "remora/dynamic"]{base} has an @deftech{expected rank} of 1 for both arguments, whereas @code[#:lang "remora/dynamic"]{+} had 0. @tech{Expected rank} is the property that determines how an argument array is split into a @tech{frame} of @tech{cells}. With @code[#:lang "remora/dynamic"]{+}, the @tech{cells} were scalars, and with @code[#:lang "remora/dynamic"]{base}, the @tech{cells} are vectors: @nested[#:style 'code-inset]{ @racketinput0[(base [[8 8 8] [7 24 60]] [2 6 7])] @racket[#,(racketresultfont (tt "[183 3274]"))]} The @tech{frames} are @code[#:lang "remora/dynamic"]{[]}, @code[#:lang "remora/dynamic"]{[2]}, and @code[#:lang "remora/dynamic"]{[]}. The last @tech[#:normalize? #f]{axis} of each argument is the shape of its @tech{rank}-1 @techlink{cells}. Expanding the second argument's frame to match the first makes it a @code[#:lang "remora/dynamic"]{[2]} frame of @code[#:lang "remora/dynamic"]{[3]} cells. Its shape becomes @code[#:lang "remora/dynamic"]{[2 3]}. This effectively treats the vector as a row, whereas @code[#:lang "remora/dynamic"]{+} treated it as a column. What if we wanted to add a matrix and a row vector? We need a function which expects @tech{rank}-1 arguments and adds them. A function is written like this: @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic (λ ((x 1) (y 1)) (+ x y)) } @code[#:lang "remora/dynamic"]{x} and @code[#:lang "remora/dynamic"]{y} are the names of the function's arguments. They are each marked with a @code[#:lang "remora/dynamic"]{1} to indicate that our function expects @tech{rank} 1 for each argument. The function body @code[#:lang "remora/dynamic"]{(+ x y)} simply adds the two @tech{rank}-1 arguments. Even if the function is applied to higher-ranked arguments, inside the function body, @code[#:lang "remora/dynamic"]{x} and @code[#:lang "remora/dynamic"]{y} always refer to rank-1 cells of those arguments. For convenience, we'll give this function a name: @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic (def vec+ (λ ((x 1) (y 1)) (+ x y))) } The @code[#:lang "remora/dynamic"]{def} form takes a name and an expression and binds the name to the result of that expression. Now let's add a matrix and a row vector: @nested[#:style 'code-inset]{ @racketinput0[(vec+ [[1 2 3] [4 5 6]] [10 20 30])] @racket[#,(racketresultfont (tt "[[11 22 33] [14 25 36]]"))]} Frames are @code[#:lang "remora/dynamic"]{[]}, @code[#:lang "remora/dynamic"]{[2]}, and @code[#:lang "remora/dynamic"]{[]}, just like when we used @code[#:lang "remora/dynamic"]{base}. We changed how the vector was expanded into a matrix by @deftech{reranking} @code[#:lang "remora/dynamic"]{+}. That is, we made a version of @code[#:lang "remora/dynamic"]{+} with different expected ranks for its arguments. Reranking is common enough in array-oriented programming that it gets special shorthand in Remora: @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic #r(1 1)+ } That's the same function as @code[#:lang "remora/dynamic"]{vec+}, written in reranking shorthand. It gives the same result: @;{TODO: this lets reader macros appear in racketinput0 but doesn't generate hyperlinks for reranked function names} @nested[#:style 'code-inset]{ @racketinput0[#,(code #:lang "remora/dynamic" "(#r(1 1)+ [[1 2 3] [4 5 6]] [10 20 30])")] @racket[#,(racketresultfont (tt "[[11 22 33] [14 25 36]]"))]} All this talk about expected rank has focused on the argument arrays, but the function array is a frame of cells too. It doesn't have to be a scalar, with just one function. @nested[#:style 'code-inset]{ @racketinput0[([magnitude angle] 3+4i)] @racket[#,(racketresultfont (tt "[5 0.9272952180016122]"))]} The expected rank for the function array is 0, no matter what functions it contains. So our frames here are @code[#:lang "remora/dynamic"]{[2]} and @code[#:lang "remora/dynamic"]{[]}. Each function cell gets applied to the one argument cell. Suppose we want both @code[#:lang "remora/dynamic"]{magnitude} and @code[#:lang "remora/dynamic"]{angle} applied to each of two complex numbers. Directly applying @code[#:lang "remora/dynamic"]{[magnitude angle]} is not what we want. That would apply @code[#:lang "remora/dynamic"]{magnitude} to one scalar cell and @code[#:lang "remora/dynamic"]{angle} to the other. Instead, we can make @code[#:lang "remora/dynamic"]{[magnitude angle]} into a single function (really, an array containing one function) which expects scalar cells: @nested[#:style 'code-inset]{ @racketinput0[#,(code #:lang "remora/dynamic" "(#r(0)[magnitude angle] [3+4i -5-12i])")] @racket[#,(racketresultfont (tt "[[5 0.9272952180016122] [13 -1.965587446494658]]"))]} The frames here are @code[#:lang "remora/dynamic"]{[]} for the function position and @code[#:lang "remora/dynamic"]{[2]} for the argument. So the whole function is replicated and applied to each of @code[#:lang "remora/dynamic"]{3+4i} and @code[#:lang "remora/dynamic"]{-5-12i}. Some functions don't expect arguments of a specific rank. They have expected rank @code[#:lang "remora/dynamic"]{all}, meaning the argument is always considered to have a scalar frame. One such function is @code[#:lang "remora/dynamic"]{head}. It extracts the first @deftech{item}, that is a sub-array with one less @tech[#:normalize? #f]{axis}. @nested[#:style 'code-inset]{ @racketinput0[(head [0 1 2 3])] @racket[#,(racketresultfont (tt "0"))]} @nested[#:style 'code-inset]{ @racketinput0[(head [[0 1] [2 3]])] @racket[#,(racketresultfont (tt "[0 1]"))]} @nested[#:style 'code-inset]{ @racketinput0[(head [[[0 1] [2 3]] [[4 5] [6 7]]])] @racket[#,(racketresultfont (tt "[[0 1] [2 3]]"))]} From a vector, we get the first element. From a matrix, we get the first row. From a rank-3 array, we get the first plane, and so on. Instead of getting a row from a matrix, we could get a column by getting the first element of each row, that is of each rank-1 cell. @nested[#:style 'code-inset]{ @racketinput0[#,(code #:lang "remora/dynamic" "(#r(1)head [[0 1] [2 3]])")] @racket[#,(racketresultfont (tt "[0 2]"))]} Another @code[#:lang "remora/dynamic"]{all}-ranked function is @code[#:lang "remora/dynamic"]{append}, which joins two arrays along their major @tech[#:normalize? #f]{axis}. @nested[#:style 'code-inset]{ @racketinput0[(append [[0 1] [2 3]] [[10 20] [30 40]])] @racket[#,(racketresultfont (tt "[[0 1] [2 3] [10 20] [30 40]]"))]} @nested[#:style 'code-inset]{ @racketinput0[(append [0 1] [2 3])] @racket[#,(racketresultfont (tt "[0 1 2 3]"))]} Reranking @code[#:lang "remora/dynamic"]{append} lets us join arrays along a different @tech[#:normalize? #f]{axis}: @nested[#:style 'code-inset]{ @racketinput0[#,(code #:lang "remora/dynamic" "(#r(1 1)append [[0 1] [2 3]] [[10 20] [30 40]])")] @racket[#,(racketresultfont (tt "[[0 1 10 20] [2 3 30 40]]"))]} @code[#:lang "remora/dynamic"]{#r(1 1)append} concatenates vectors. Applying it to two matrices concatenates corresponding vector cells and reassembles them in the vector frame to produce a new matrix. For most functions, the output shape is determined by the argument shapes. When we append a @code[#:lang "remora/dynamic"]{[2]}-vector and a @code[#:lang "remora/dynamic"]{[3]}-vector, we know we will get a @code[#:lang "remora/dynamic"]{[5]}-vector. Adding a @code[#:lang "remora/dynamic"]{[3 6]}-matrix and a @code[#:lang "remora/dynamic"]{[3]}-vector will always produce a @code[#:lang "remora/dynamic"]{[3 6]}-matrix. Some functions' output shape depends on the actual values of the input atoms, not just shapes. If we apply such a function to a multi-celled array, we could get result cells with differing shapes. We can't put those together in a single array. There is no valid shape that describes that array. An array can only have one size along each @tech[#:normalize? #f]{axis}. In order to make such functions safe to use on higher-ranked arguments, they produce @deftech{boxes}. @nested[#:style 'code-inset]{ @racketinput0[(iota [2 3])] @racket[#,(racketresultfont (tt "(box [[0 1 2] [3 4 5]])"))]} @nested[#:style 'code-inset]{ @racketinput0[(iota [4 2])] @racket[#,(racketresultfont (tt "(box [[0 1] [2 3] [4 5] [6 7]])"))]} A box is a scalar datum which may contain an array of any shape. Producing boxes makes it safe to lift @code[#:lang "remora/dynamic"]{iota}: @nested[#:style 'code-inset]{ @racketinput0[(iota [[2 3] [4 2]])] @racket[#,(racketresultfont (tt (string-append "[(rem-box [[0 1 2] [3 4 5]]) " "(rem-box [[0 1] [2 3] [4 5] [6 7]])]")))]} The result has shape @code[#:lang "remora/dynamic"]{[2]}. Its items are boxes. The first box contains a @code[#:lang "remora/dynamic"]{[2 3]}-array, and the second contains a @code[#:lang "remora/dynamic"]{[4 2]}-array. The @code[#:lang "remora/dynamic"]{unbox} form allows the contents of a box to be bound to a variable: @nested[#:style 'code-inset]{ @racketinput0[(unbox nats (iota [5]) (foldr * 1 (add1 nats)))] @racket[#,(racketresultfont (tt "120"))]} We temporarily had a vector with ``unknown'' length while computing 5!. Folding eliminates the unknown length by producing a scalar. This means we could safely replace @code[#:lang "remora/dynamic"]{5} with an unknown natural number. Our unknown-length vector is folded into a scalar, making it safe to return without boxing it. This means we could write a factorial function: @codeblock[#:keep-lang-line? #f]{ #lang remora/dynamic (λ ((n 0)) (unbox nats (iota [n]) (foldr * 1 (add1 nats)))) } However, if we write a function that adds 1 to a box's contents, safety demands that the function return a box. Otherwise, applying it to an argument like @code[#:lang "remora/dynamic"]{(iota [[2 3] [4 2]])} would fail.
false
716258d1b263b70d67427735bcba62c5292e9e69
bc38b888675e831a3ec99268be7f5f90a3b5ac9a
/fontland/table/cff/cff-operand.rkt
fefbaae091b2bc4ce56282eb15db93e3b3e8553b
[ "MIT" ]
permissive
mbutterick/fontland
c3dd739a5c36730edeca3838225dc8a0c285051b
1c1d7db48f2637f7a226435c4fef39a7037204b7
refs/heads/master
2022-02-03T19:48:29.543945
2022-01-08T15:58:14
2022-01-08T15:58:14
157,796,528
12
0
null
null
null
null
UTF-8
Racket
false
false
4,445
rkt
cff-operand.rkt
#lang debug racket/base (require racket/class xenomorph "cff-struct.rkt") (provide CFFOperand) #| approximates https://github.com/mbutterick/fontkit/blob/master/src/cff/CFFOperand.js |# (define FLOAT_EOF #xf) (define FLOAT_LOOKUP (vector "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "." "E" "E-" "" "-")) (define FLOAT_ENCODE_LOOKUP (hash "." 10 "E" 11 "E-" 12 "-" 14)) (define CFFOperand% (class x:base% (super-new) (define/augment (x:decode stream _ value) (cond [(<= 32 value 246) (- value 139)] [(<= 247 value 250) (+ (* (- value 247) 256) (read-byte stream) 108)] [(<= 251 value 254) (- (* (- 251 value) 256) (read-byte stream) 108)] [(= value 28) (decode int16be stream)] [(= value 29) (decode int32be stream)] [(= value 30) (for/fold ([strs null] [break? #false] #:result (* (string->number (apply string-append (reverse strs))) 1.0)) ([i (in-naturals)] #:break break?) (define b (read-byte stream)) (define n1 (arithmetic-shift b -4)) (cond [(= n1 FLOAT_EOF) (values strs 'break-now)] [else (let ([strs (cons (vector-ref FLOAT_LOOKUP n1) strs)]) (define n2 (bitwise-and b 15)) (cond [(= n2 FLOAT_EOF) (values strs 'break-now)] [else (let ([strs (cons (vector-ref FLOAT_LOOKUP n2) strs)]) (values strs #false))]))]))])) (define/augment (x:size value-arg _) ;; if the value needs to be forced to the largest size (32 bit) ;; e.g. for unknown pointers, set to 32768 (define value (cond [(Ptr? value-arg) (if (Ptr-forceLarge value-arg) 32768 (Ptr-val value-arg))] [else value-arg])) (cond [(not (integer? value)) ; floating point (define str (number->string value)) (add1 (ceiling (/ (add1 (string-length str)) 2)))] [(<= -107 value 107) 1] [(<= -1131 value 1131) 2] [(<= -32768 value 32767) 3] [else 5])) (define (string->inexact str) (string->number str 10 'number-or-false 'decimal-as-inexact)) (define/augment (x:encode value-arg stream . _) ;; if the value needs to be forced to the largest size (32 bit) ;; e.g. for unknown pointers, save the old value and set to 32768 (define value (if (Ptr? value-arg) (Ptr-val value-arg) value-arg)) (define val (if value (string->inexact (format "~a" value)) 0)) (cond [(and (Ptr? value-arg) (Ptr-forceLarge value-arg)) (encode uint8 29 stream) (encode int32be val stream)] [(not (integer? val)) ;; floating point (encode uint8 30 stream) (define str (list->vector (regexp-match* #rx"." (number->string val)))) (define n2 (for/last ([i (in-range 0 (vector-length str) 2)]) (define c1 (vector-ref str i)) (define n1 (hash-ref FLOAT_ENCODE_LOOKUP c1 (string->number c1))) (define n2 (cond [(= i (sub1 (vector-length str))) FLOAT_EOF] [else (define c2 (vector-ref str (add1 i))) (hash-ref FLOAT_ENCODE_LOOKUP c2 (string->number c2))])) (encode uint8 (bitwise-ior (arithmetic-shift n1 4) (bitwise-and n2 15)) stream) n2)) (unless (= n2 FLOAT_EOF) (encode uint8 (arithmetic-shift FLOAT_EOF 4) stream))] [(<= -107 value 107) (encode uint8 (+ val 139) stream)] [(<= 108 value 1131) (let ([val (- val 108)]) (encode uint8 (+ (arithmetic-shift val -8) 247) stream) (encode uint8 (bitwise-and val #xff) stream))] [(<= -1131 value -108) (let ([val (- (+ val 108))]) (encode uint8 (+ (arithmetic-shift val -8) 251) stream) (encode uint8 (bitwise-and val #xff) stream))] [(<= -32768 value 32767) (encode uint8 28 stream) (encode uint16be val stream)] [else (encode uint8 29 stream) (encode uint32be val stream)])))) (define CFFOperand (make-object CFFOperand%))
false
2005167d7570bc1e8f075b8433ebdca7ef5277cc
ea28b962949105fb27622bad2de8a7e0c765f1f2
/ins2.rkt
d700cbf62cb073260a5b5508d29944e7aad8cb90
[]
no_license
even4void/scratch
5493c213036f7ba36ec9921de0abc7c3eb29287a
d6d58148753ca77800ddc04b56240eba621bc86a
refs/heads/master
2023-06-08T22:05:00.563639
2023-05-27T17:49:34
2023-05-27T17:49:34
191,911,467
0
0
null
null
null
null
UTF-8
Racket
false
false
721
rkt
ins2.rkt
#lang racket (require srfi/1) ;; span!, append! (require srfi/26) ;; cut (define (isort lst (lt? <)) (foldr (lambda (item sorted) (let-values (((lhs rhs) (span! (cut lt? <> item) sorted))) (append! lhs (cons item rhs)))) '() lst)) (define l '(44 40 65 79 42 82 46 33 57 100 23 98 28 35 6 63 88 18 20 81 83 38 67 17 56 74 60 39 61 76 53 66 73 25 19 50 70 93 92 14 37 8 4 15 27 55 13 64 71 10 5 2 75 77 7 9 11 49 43 91 85 72 32 26 97 99 34 86 96 78 90 59 24 31 94 80 45 12 95 1 16 84 62 68 87 58 29 51 52 69 48 3 21 22 54 47 36 41 30 89)) (isort l)
false
50ec6ee5f2e792f829680c9f20c793888140b131
4016b36583cdc169e9b8afced5d83fe98b18bca5
/misc_find_slow_cores.rkt
727cf82a80a46aa4a4e92d65b777e3590d381891
[ "MIT" ]
permissive
mcoram/primrec
39478e512f147e6e0c5bd299590e9b97c976e1e9
1255c7f0b78ade4a3a59bfcf1128d2763f650403
refs/heads/master
2021-01-19T14:06:47.787267
2013-09-06T20:29:06
2013-09-06T20:29:06
11,691,853
1
0
null
null
null
null
UTF-8
Racket
false
false
4,475
rkt
misc_find_slow_cores.rkt
#lang racket (require "pr_primitives.rkt") (require "predict-extension.rkt") (require racket/set) (require "util.rkt") ; The goal of this script was to find (R0 ...) and (R1 ...) cores (i.e. subtrees that do not include further R0 or R1 calls) that contribute to the slowdown of functions ; the thought is that replacing them with specialized code (that uses induction to bypass the loop) will speed things up substantially. ; Fortunately, it looks like all the relevant cores are of very simple types that I can optimize. (define (find-subtrees-in t set1) (define result '()) (if (list? t) (begin (when (symbol? (first t)) (when (set-member? set1 (first t)) (set! result (cons t result)))) (apply append (cons result (map (lambda (x) (find-subtrees-in x set1)) t)))) result)) (define (are-used-internally? t set1) (if (list? t) (for/or ([x (cdr t)]) (are-used? x set1)) #f)) (define (are-used? t set1) (if (list? t) (for/or ([x t]) (are-used? x set1)) (if (symbol? t) (set-member? set1 t) #f))) ;(define tst (third (nth a1l 50))) ;(define tstl (find-subtrees-in tst (list->set '(R0 R1)))) ;(filter (lambda (x) (not (are-used-internally? x (list->set '(R0 R1))))) tstl) (define (core-subtrees-in t set1) (filter (lambda (x) (not (are-used-internally? x set1))) (find-subtrees-in t set1))) ;(core-subtrees-in tst (list->set '(R0 R1))) (define (make-corel l) (set->list (list->set (apply append (map (lambda (x) (core-subtrees-in (third x) (list->set '(R0 R1)))) l))))) (define core0l (make-corel a0l)) ;'((R1 (C13 S P32) S) (R1 (C13 S P32) P11) (R1 (C13 S (C13 S P32)) S) (R1 (C13 S (C13 S P32)) P11)) ;!? that's it? (define core1l (make-corel a1l)) (define a1sl (filter (lambda (x) (>= (abs (fifth x)) 1)) a1l)) (define core1sl (make-corel a1sl)) ; The cases got totally out of hand here. sigh. (define (cmp-t x y) (if (equal? x 0) (if (equal? y 0) 0 -1) (if (equal? y 0) 1 (if (symbol? x) (if (symbol? y) (let ([sx (symbol->string x)] [sy (symbol->string y)]) (if (string<? sx sy) -1 (if (string>? sx sy) 1 0))) -1) (if (symbol? y) 1 (if (not (equal? (length x) (length y))) (let ([lx (length x)] [ly (length y)]) (if (< lx ly) -1 (if (> lx ly) 1 0))) (if (equal? (length x) 0) 0 (let ([c1 (cmp-t (car x) (car y))]) (if (equal? c1 0) (cmp-t (cdr x) (cdr y)) c1))))))))) (define (<-t x y) (< (cmp-t x y) 0)) (sort core1sl <-t) ;Compilation targets: ; (R0 P21 0) ; (R0 P21 (C10 S 0)) ; (R0 P22 0) ; (R0 (C12 S (C12 S P21)) 0) ; (R0 (C12 S (C12 S P22)) 0) ; (R0 (C12 S (C12 S (C12 S P21))) 0) ; (R0 (C12 S (C12 S (C12 S P22))) 0) ; (R0 (C12 S (C12 S (C12 S (C12 S P21)))) 0) ; (R0 (C12 S (C12 S (C12 S (C12 S P22)))) 0) ; (R0 (C12 S (C12 S (C12 S (C12 S (C12 S P21))))) 0) ; (R0 (C12 S (C12 S (C12 S (C12 S (C12 S P22))))) 0) ; (R0 (C12 S (C12 S (C12 S (C12 S (C12 S (C12 S (C12 S P21))))))) 0) ; (R1 P31 P11) ; (R1 P31 S) ; (R1 P31 (C11 S S)) ; (R1 P31 (C11 S (C11 S S))) ; (R1 P31 (C11 S (C11 S (C11 S S)))) ; (R1 P31 (C11 S (C11 S (C11 S (C11 S S))))) ; (R1 P33 S) ; (R1 P33 (C11 S S)) ; (R1 P33 (C11 S (C11 S S))) ; (R1 P33 (C11 S (C11 S (C11 S S)))) ; (R1 P33 (C11 S (C11 S (C11 S (C11 S S))))) ; (R1 (C13 S P31) P11) ; (R1 (C13 S P32) P11) ; (R1 (C13 S P32) S) ; (R1 (C13 S P33) P11) ; (R1 (C13 S (C13 S P31)) P11) ; (R1 (C13 S (C13 S P32)) P11) ; (R1 (C13 S (C13 S P32)) S) ; (R1 (C13 S (C13 S P33)) P11) ; (R1 (C13 S (C13 S (C13 S P31))) P11) ; (R1 (C13 S (C13 S (C13 S P32))) P11) ; (R1 (C13 S (C13 S (C13 S P32))) S) ; (R1 (C13 S (C13 S (C13 S P33))) P11) ; (R1 (C13 S (C13 S (C13 S (C13 S P31)))) P11) ; (R1 (C13 S (C13 S (C13 S (C13 S P32)))) P11) ; (R1 (C13 S (C13 S (C13 S (C13 S P32)))) S) ; (R1 (C13 S (C13 S (C13 S (C13 S P33)))) P11) ; (R1 (C13 S (C13 S (C13 S (C13 S (C13 S P32))))) P11) ; (R1 (C13 S (C13 S (C13 S (C13 S (C13 S P32))))) S) ; (R1 (C13 S (C13 S (C13 S (C13 S (C13 S (C13 S P32)))))) P11) ; (R1 (C13 S (C13 S (C13 S (C13 S (C13 S (C13 S P33)))))) P11))
false
b8f764ba7d7158705b37c1026a736b9ddabb6998
1bdc6c054a5249644466bfde8c21fd5e848514bb
/2017/hw3/SICP2.58b.rkt
3e51f04a51a4a4daad6360c6ae6ebcfb4cedbb1e
[]
no_license
fuguigui/racket
9ad8483bd8547194ff7cfa84e2ee3f4fbba7cbf4
dc538028ef6b2a1411909bd3a613b7028c6f56c5
refs/heads/master
2021-01-18T22:56:21.352936
2017-06-21T09:29:58
2017-06-21T09:29:58
84,380,381
0
0
null
2017-04-20T02:08:41
2017-03-09T00:38:56
Racket
UTF-8
Racket
false
false
2,936
rkt
SICP2.58b.rkt
#lang racket (define (number? exp) (if (pair? exp) #f (not (symbol? exp)))) (define (variable? exp) (if (pair? exp)#f (symbol? exp))) (define (same-variable? exp var) (if (variable? exp) (eq? exp var) #f)) (define (search-loop op lst) (if (null? lst) lst (if (eq? (car lst) op) lst (search-loop op (cdr lst))))) (define (cutexp old cutout) (if (eq? old cutout) '() (cons (car old) (cutexp (cdr old) cutout)))) (define (sum? exp) (if (pair? exp) (if (pair? (car exp)) (sum? (cdr exp)) (if (eq? (car exp) '+)#t (sum? (cdr exp)))) #f)) (define (addend exp) (define add (cutexp exp (search-loop '+ exp))) (if(null? (cdr add)) (car add) add)) (define (augend exp) (define aug (cdr (search-loop '+ exp))) (if (null? (cdr aug)) (car aug) aug)) (define (make-sum add aug) (cond ((and (number? add) (number? aug)) (+ add aug)) ((eq? add 0) aug) ((eq? aug 0) add) ((pair? aug) (if (pair? add) (append add (list '+) aug) (append (list add '+) aug))) ((pair? add) (append add (list '+ aug))) (else (list add '+ aug)))) (define (product? exp) (if (pair? exp) (if (pair? (car exp)) (product? (cdr exp)) (if (eq? (car exp) '*)#t (product? (cdr exp)))) #f)) (define (multiplier exp) (define nexp (cutexp exp (search-loop '* exp))) (if (null? (cdr nexp)) (car nexp) nexp)) (define (multiplicand exp) (define nexp(cdr (search-loop '* exp))) (if (null? (cdr nexp)) (car nexp) nexp)) (define (make-product plier plicand) (cond ((and (number? plier) (number? plicand)) (* plier plicand)) ((eq? plier 0)0) ((eq? plicand 0)0) ((eq? plier 1)plicand) ((eq? plicand 1)plier) ((pair? plicand) (list plier '* plicand)) ((pair? plier) (list plier '* plicand)) (else (list plier '* plicand)))) (define (deriv exp var) (cond ((number? exp ) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) ((sum? exp) (make-sum (deriv (addend exp) var) (deriv (augend exp) var))) ((product? exp) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp)))) (else (error "wrong format")))) (define (myloop) (let ((a (read))) (if (eq? a eof) (void) (begin (display (deriv a 'x)) (newline) (myloop))))) (myloop) ;0 ;x ;(x * 3) ;(y + x) ;(y * x) ;(x * x + x * y) ;(x * x * x) ;(x * x * y) ;(x * x + x * x * y * (x + 3) + x * y)
false
a269d290920a3b73da4a5d9b57d6925f26f26d25
fcabe53f2a2df3bf873365eca25f81fa975122ac
/racket-cas/normalize.rkt
0c706bc1cca94d1dd4f00e18b0cd98a02f86ff9e
[]
no_license
soegaard/racket-cas
bb1dd8aad4fc9462080a3458368a43e713c036b8
f5cced27a7ce135a02fed98216cdf668e55eee86
refs/heads/master
2023-08-17T03:53:41.991620
2023-08-02T12:42:33
2023-08-02T12:42:33
15,660,051
66
10
null
2020-03-10T13:40:59
2014-01-05T22:35:02
Racket
UTF-8
Racket
false
false
4,594
rkt
normalize.rkt
#lang racket/base (provide normalize) ;;; ;;; Normalization ;;; (require racket/match math/bigfloat (except-in "bfracket.rkt" denominator numerator) "core.rkt" "math-match.rkt" "parameters.rkt" "compose-app.rkt" "logical-operators.rkt" "relational-operators.rkt" "trig.rkt" "complex.rkt" "standard-functions.rkt") (module+ test (require rackunit math/bigfloat "parameters.rkt") (define x 'x) (define y 'y) (define z 'z)) ; normalize will given a non-canonical form u ; return the corresponding canonical form. ; Note: In normalized expressions all numbers are real. ; A complex number, say, 2+3i, is rewritten to (+ 2 (* 3 @i)) (define (normalize u) (when debugging? (displayln (list 'normalize u))) (define (normalize-complex-number r) (define a (real-part r)) (define b (imag-part r)) (if (zero? a) (⊗ @i b) (⊕ (⊗ @i b) a))) (define n normalize) (math-match u [r #:when (real? r) r] ; fast path [r (normalize-complex-number r)] [r.bf r.bf] [#t #t] [#f #f] [x x] [(⊕ u) (n u)] [(⊕ u v) (⊕ (n u) (n v))] [(⊗ u) (n u)] [(⊗ u v) (⊗ (n u) (n v))] [(And u v) (And (n u) (n v))] [(Or u v) (Or (n u) (n v))] [(And u) (And (n u))] [(Or u) (Or (n u))] [(Expt u v) (Expt (n u) (n v))] [(Equal u v) (Equal (n u) (n v))] ; xxx [(Less u v) (Less (n u) (n v))] [(LessEqual u v) (LessEqual (n u) (n v))] [(Greater u v) (Greater (n u) (n v))] [(GreaterEqual u v) (GreaterEqual (n u) (n v))] [(Ln u) (Ln (n u))] [(Log u) (Log (n u))] [(Log u v) (Log (n u) (n v))] [(Sin u) (Sin (n u))] [(Asin u) (Asin (n u))] [(Atan u) (Atan (n u))] [(Cos u) (Cos (n u))] [(Acos u) (Acos (n u))] [(Atan u) (Atan (n u))] [(Cosh u) (Cosh (n u))] [(Sinh u) (Sinh (n u))] [(Abs u) (Abs (n u))] [(Magnitude u) (Magnitude (n u))] [(Angle u) (Angle (n u))] [(Factorial u) (Factorial (n u))] [(Gamma u) (Gamma (n u))] [(Prime? u) (Prime? (n u))] [(Odd-prime? u) (Odd-prime? (n u))] [(Nth-prime u) (Nth-prime (n u))] [(Random-prime u) (Random-prime (n u))] [(Next-prime u) (Next-prime (n u))] [(Prev-prime u) (Prev-prime (n u))] [(Divisors u) (Divisors (n u))] [(Piecewise us vs) (list* 'piecewise (map list (map n us) (map n vs)))] [(app: f us) (match u [(list '/ u v) (⊘ (n u) (n v))] [(list '- u) (⊖ (n u))] [(list '- u v) (⊖ (n u) (n v))] [(list 'tan v) (Tan (n v))] [(list 'sqr u) (Sqr (n u))] [(list 'sqrt u) (Sqrt (n u))] [(list 'root u m) (Root (n u) (n m))] [(list 'exp u) (Exp (n u))] [(list 'bf u) (number? u) (bf u)] [(list* 'or us) (apply Or: us)] [(cons '< us) (n (cons 'Less us))] [(cons '≤ us) (n (cons 'LessEqual us))] [(cons '> us) (n (cons 'Greater us))] [(cons '≥ us) (n (cons 'GreaterEqual us))] [_ (let ([nus (map n us)]) (if (equal? us nus) u (n `(,f ,@nus))))])])) (module+ test (displayln "TEST - normalize") (check-equal? (normalize '(+ 1 x (* (expt (sin (ln (cos (asin (acos (sqrt (tan x))))))) 2)))) (⊕ 1 x (⊗ (Expt (Sin (Ln (Cos (Asin (Acos (Sqrt (Tan x))))))) 2)))) (check-equal? (normalize '(/ (- x) (+ (- x y) (exp x) (sqr x) (+ 3)))) (⊘ (⊖ x) (⊕ (⊖ x y) (Exp x) (Sqr x) (⊕ 3)))) (check-equal? (normalize '(bf 3)) (bf 3)) (check-equal? (normalize '(f (- x y))) `(f ,(⊖ x y))) (check-equal? (normalize '(log 3)) '(log 10 3)) ; check that complex numbers are normalized to the form (+ a (* b @i)) (check-equal? (normalize +i) '@i) (check-equal? (normalize 1+i) '(+ @i 1)) (check-equal? (normalize +2i) '(* @i 2)) ; check that @i appears as the first symbol in products (check-equal? (normalize '(* 2 x a z 3 y @a @z @i )) '(* @i 6 @a @z a x y z)))
false
4394d605fbc7be25a62afd4cffc07a045decefc1
a680b8ee1f05ae512b991ea6c9cadc725d5d6e7d
/expeditor-lib/private/assert.rkt
fa0bdaed8e639d56ad9df8cce8befb2bfdcf7acc
[ "MIT", "Apache-2.0" ]
permissive
greghendershott/expeditor
8ae3e078fb765317fd0b688cd850b26970af08f8
5b1a374084edfc9b39bcccce5c8219b989496b42
refs/heads/master
2023-08-30T03:40:10.972709
2021-11-17T01:32:22
2021-11-17T01:36:49
null
0
0
null
null
null
null
UTF-8
Racket
false
false
213
rkt
assert.rkt
#lang racket/base (provide assert*) (define-syntax assert* (syntax-rules () [(_ expr ...) (begin (assert expr) ...)])) (define (assert expr) (unless expr (error "assertion failed: ~s" 'expr)))
true
f7977b9c98d2ef6af32b1b2a8af663723bfb39c9
19e1f84404c72915edc81d147a00b8d2cc59cbd4
/deta-lib/private/schema.rkt
844f8faeb1b517b2ee58e19a16c9678412dd226c
[ "BSD-3-Clause" ]
permissive
otherjoel/deta
7ca5815850cd08ec143aae73e678b47d274981d1
56f0eb108a8f4c4f73ea021a9823557c5d4a0c87
refs/heads/master
2020-12-05T14:57:49.169940
2019-12-29T17:08:27
2019-12-29T17:08:27
232,146,704
1
0
null
2020-01-06T17:03:51
2020-01-06T17:03:49
null
UTF-8
Racket
false
false
1,940
rkt
schema.rkt
#lang racket/base (require racket/contract racket/match "field.rkt") ;; struct ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (provide make-schema (struct-out schema)) (struct schema (id table virtual? struct-ctor struct-pred meta-updater pre-persist-hook pre-delete-hook fields primary-key)) (define (make-schema #:id id #:table table #:virtual? virtual? #:struct-ctor struct-ctor #:struct-pred struct-pred #:meta-updater meta-updater #:pre-persist-hook pre-persist-hook #:pre-delete-hook pre-delete-hook #:fields fields) (define the-schema (schema id table virtual? struct-ctor struct-pred meta-updater pre-persist-hook pre-delete-hook fields (findf field-primary-key? fields))) (begin0 the-schema (unless virtual? (register! id the-schema)))) ;; registry ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (provide schema-registry-lookup) (define/contract schema-registry (parameter/c (hash/c symbol? schema?)) (make-parameter (hasheq))) (define (register! id schema) (define registry (schema-registry)) (when (hash-has-key? registry id) (raise-user-error 'register! "schema ~a conflicts with a previous one" id)) (schema-registry (hash-set registry id schema))) (define/contract (schema-registry-lookup schema-or-id) (-> (or/c schema? symbol?) schema?) (define schema (match schema-or-id [(? schema?) schema-or-id ] [(? symbol?) (hash-ref (schema-registry) schema-or-id #f)])) (unless schema (raise-argument-error 'lookup-schema "unregistered schema" schema-or-id)) schema)
false
9860c3d77486a758b1653307757e117f7fb7a2d4
fdbcd4128e32d9f30ca9fc34ef3f85036c07afa0
/vector3.rkt
dc020132d139ff9d16baba30fc248631814ede74
[]
no_license
Xuvasi/earthgen
e5c87255b8bf12e00c31d364b519fb16bf07537d
447265311acba8d093ea9e346131b043169a3c7d
refs/heads/master
2021-01-12T20:41:44.103372
2014-01-08T20:47:07
2014-01-08T20:47:07
null
0
0
null
null
null
null
UTF-8
Racket
false
false
2,913
rkt
vector3.rkt
#lang typed/racket (require math/flonum racket/vector) (provide flvector3 flvector3-zero flvector3-scale flvector3-length flvector3-length-squared flvector3-distance flvector3-distance-squared flvector3-normal flvector3+ flvector3- flvector3-dot-product flvector3-cross-product flvector3-map-mult) (define-type flvector3 FlVector) (: flvector3-zero (-> flvector3)) (define (flvector3-zero) (flvector 0.0 0.0 0.0)) (: flvector3-length-squared (flvector3 -> Flonum)) (define (flvector3-length-squared v) (flvector-sum (flvector-sqr v))) (: flvector3-length (flvector3 -> Flonum)) (define (flvector3-length v) (flsqrt (flvector3-length-squared v))) (: flvector3-distance-squared (flvector3 flvector3 -> Flonum)) (define (flvector3-distance-squared v u) (flvector3-length-squared (flvector3- v u))) (: flvector3-distance (flvector3 flvector3 -> Flonum)) (define (flvector3-distance v u) (flvector3-length (flvector3- v u))) (: flvector3-scale (flvector3 Flonum -> flvector3)) (define (flvector3-scale v a) (flvector-scale v a)) (: flvector3-normal (flvector3 -> flvector3)) (define (flvector3-normal a) (if (zero? (flvector3-length a)) a (flvector3-scale a (/ (flvector3-length a))))) (: flvector3+ (flvector3 * -> flvector3)) (define (flvector3+ . vecs) (foldl flvector+ (flvector3-zero) vecs)) (: flvector3- (flvector3 flvector3 * -> flvector3)) (define (flvector3- v . vecs) (if (empty? vecs) (flvector- v) (foldl (lambda: ([b : flvector3] [a : flvector3]) (flvector- a b)) v vecs))) (: mult (Flonum Flonum * -> Flonum)) (define (mult a . n) (foldl * a n)) (: flvector3-map-mult (flvector3 * -> flvector3)) (define (flvector3-map-mult . vecs) (foldl (lambda: ([v : flvector3] [u : flvector3]) (flvector-map mult v u)) (flvector 1.0 1.0 1.0) vecs)) (: flvector3-dot-product (flvector3 flvector3 -> Flonum)) (define (flvector3-dot-product v u) (flvector-sum (flvector-map mult v u))) (: remap (flvector3 (Vectorof Integer) -> flvector3)) (define (remap v m) (let ([elm (lambda: ([v : flvector3] [m : (Vectorof Integer)] [i : Integer]) (flvector-ref v (vector-ref m i)))]) (flvector (elm v m 0) (elm v m 1) (elm v m 2)))) (: col (flvector3 (Vectorof Integer) flvector3 (Vectorof Integer) -> flvector3)) (define (col v m u n) (flvector-map mult (remap v m) (remap u n))) (: flvector3-cross-product (flvector3 flvector3 -> flvector3)) (define (flvector3-cross-product v u) (let* ([m (vector 1 2 0)] [n (vector 2 0 1)]) (flvector3- (col v m u n) (col v n u m))))
false
fc0e1a0a1ccb8da85cfdcb1ce480d165a154d12d
4113cc9017d7227ae9969dd4d927524a104e8f50
/bib-lang.rkt
07a7eae23feedc7fb9a427d0d171a69b0618f1cf
[ "MIT" ]
permissive
spdegabrielle/bib-lang-test
03bb56239b4b80114c857c5cd9c7ae7770806e31
39667435b71c979b42baf409c08cb87c74f0104c
refs/heads/main
2023-03-12T05:43:05.804997
2021-03-07T12:04:48
2021-03-07T12:04:48
345,335,037
0
0
null
null
null
null
UTF-8
Racket
false
false
1,049
rkt
bib-lang.rkt
#lang at-exp racket/base (require scribble/manual scribble/core scribble/html-properties scribble/latex-properties scriblib/render-cond racket/runtime-path setup/collects racket/list racket/format (only-in xml cdata) (only-in racket/match match) (only-in racket/system process) (only-in racket/port port->string) (for-syntax racket/base) (for-syntax racket/format)) (provide (except-out (all-from-out racket/base) #%module-begin) (rename-out [module-begin #%module-begin]) title author date location url cat) (define-syntax-rule (module-begin expr ...) (#%module-begin (define ref (quasiquote (~a ...))) (provide ref))) (define (author t) ~a{"Author:" @t}) (define (date t) ~a{"Date:" @t}) (define (location t) ~a{"Location:" @t}) (define (url l) ~a{"URL:" @(hyperlink l l)}) (define (cat t) ~a{"cat:" @t})
true
84ed2c0841139f021bf7834223e9a05fc7c8e2c3
34b0da7b0976a9d0528a0a9e76e7401de2b3a76b
/week5/-remove-duplicates.rkt
dfb2388c9433062386715cec8cd062d83da7bb60
[]
no_license
amuskova/Functional-Programing
4ec8565f0132e12d11e2ce959fa6025300f3d639
5c6dcebe17b51321f1fc44efa6e2629c0846c623
refs/heads/main
2023-03-05T15:47:59.963797
2021-02-17T22:24:11
2021-02-17T22:24:11
339,671,573
0
0
null
null
null
null
UTF-8
Racket
false
false
1,100
rkt
-remove-duplicates.rkt
#lang racket (require rackunit) (require rackunit/text-ui) ; remove-duplicates ; премахва всички повтарящи се елементи от списъка (define (remove-first x xs) (cond ((null? xs) '()) ((= x (car xs)) (cdr xs)) (else (cons (car xs) (remove-first x (cdr xs)))))) ; find-min - връща ни най-малкото число от непразен списък (define (find-min xs) (cond ((null? (cdr xs)) (car xs)) (else (min (car xs) (find-min (cdr xs)))))) (define (selection-sort xs) (if (null? xs) '() (cons (find-min xs) (selection-sort (remove-first (find-min xs) xs))))) (define (remove-duplicates xs) (define (remove xs) (cond ((null? xs) '()) ((= (car xs) (car (cdr xs))) (remove (cdr xs))) (else (cons (car xs) (remove (cdr xs)))))) (remove (selection-sort xs)) ) (define tests (test-suite "remove-duplicates" (check-equal? (remove-duplicates '(1 1 2 2 1 3 3 2 3)) '(1 2 3)) (check-equal? (remove-duplicates '(1 2 3)) '(1 2 3)) ) ) (run-tests tests 'verbose)
false
4de1d6bf39c307bcc38b739a2e7530a80fa1c145
ba5171ca08db9e0490db63df59ee02c85a581c70
/homework/1/squares-solution2.rkt
443af4d3368c45e61a335259a93d0bb1bc54e9e8
[]
no_license
semerdzhiev/fp-2020-21
030071ed14688751d615b1d1d39fa406c131a285
64fa00c4f940f75a28cc5980275b124ca21244bc
refs/heads/master
2023-03-07T10:17:49.583008
2021-02-17T11:46:08
2021-02-17T11:46:08
302,139,037
31
16
null
2021-01-17T15:22:17
2020-10-07T19:24:33
Racket
UTF-8
Racket
false
false
1,209
rkt
squares-solution2.rkt
; accumulate -- the version from the lecture slides (define (accumulate op term init a next b) (define (loop i) (if (<= i b) (op (term i) (loop (next i)) ) init )) (loop a) ) (define (squares n) ; The #<void> value. If not using R5RS, simply define v to be (void) (define v (display "")) ; identity (define (id x) x) ; increment (define (1+ n) (+ 1 n)) ; Display pre, then display elem n-times and then display post (define (display-x elem n pre post) (define (op x y) (display elem)) (display pre) (accumulate op id v 1 1+ n) (display post) ) ; Displays one line of the figure, using ; corner-left and corner-right when printing the ; corners of a square (define (line i corner-left corner-right) (display-x "│ " (- n i) "" "") (display-x #\─ (- (* i 4) 3) corner-left corner-right) (display-x " │" (- n i) "" "") (display #\newline) ) (define (top i) (line i #\┌ #\┐)) (define (bottom i) (line i #\└ #\┘)) (define (loop n f term) (define (op i result) (f i)) (accumulate op term v 1 1+ n) ) (loop n top id) (loop n bottom (lambda (i) (+ 1 (- n i)))) ) (squares 10)
false
6ec8f28d9c225ab8a9f467d0c22b834dc78f3f39
5130312f0f3831ada0801a5b73995c9c501d15f7
/out/binary-stl.rkt
9ad1ed06211beada6b2f23d1cba4f1a89d07564d
[ "Apache-2.0" ]
permissive
zen3d/ruckus
5f6ee5f03d764332a889ac7d64e56c11613847f7
45c5928376092ca911afabfba73af28877c87166
refs/heads/master
2020-04-13T17:23:24.756503
2018-12-28T00:36:06
2018-12-28T00:36:06
163,346,905
5
0
NOASSERTION
2018-12-28T00:14:11
2018-12-28T00:14:11
null
UTF-8
Racket
false
false
2,492
rkt
binary-stl.rkt
#lang racket ; Binary STL output. (provide surface->stl) (require "../core/math.rkt") (require "../core/compiler/racket.rkt") (require "../lang/evaluator.rkt") ; Takes an unevaluated design generator 'gen', a region of interest size ; 'size', and a quantum 'q' and generates STL for any surfaces within the ROI. ; ; The function 'subdivide' will be used to subdivide space into 'q'-sized cubes. ; ; The function 'polygonize' will be used to ; ; Both 'size' and 'q' are given in the same (design) units. ; ; Output is to 'current-output-port'. (define (surface->stl gen size q subdivide polygonize) (let ([f (node->distance-function (call-with-edsl-root gen))]) ; STL header. (write-bytes (make-bytes 80 32)) ; Placeholder for number-of-triangles, TBD. (write-bytes (make-bytes 4 0)) (define triangle-count 0) (define (emit tri) (when (write-stl-tri tri) (set! triangle-count (add1 triangle-count)))) (subdivide f size q (lambda (gc) (polygonize gc emit))) ; Return to the length and fill in our final tally. (file-position (current-output-port) 80) (write-bytes (integer->integer-bytes triangle-count 4 #f )) (void))) ; Writes the triangle 'tri' (a 3-list of vec3) to current-output-port as a ; binary STL triangle record, iff it is not degenerate. ; ; If the record is written, the result is #t. If not, it is #f. (define (write-stl-tri tri) ; Compute the cross product so we can find the face normal. (let* ([ba (vec3-sub (second tri) (first tri))] [ca (vec3-sub (third tri) (first tri))] [cross (vec3-cross ba ca)]) ; Omit degenerate triangles (zero-length cross). (if (zero? (vec3-length cross)) #f ; Generate and write a binary-format record. Binary format records ; consist of: ; - The normal vector (12 bytes) ; - The triangle vertices (3 * 12 bytes) ; - Two trailing bytes upon which nobody agrees (2 bytes) (let ([buf (make-bytes (+ 12 (* 3 12) 2))]) (vector->stl-bytes (vec3-normalize cross) buf 0) ; Three corner vectors (for ([p (in-list tri)] [off (in-range 12 48 12)]) (vector->stl-bytes p buf off)) (write-bytes buf) #t)))) (define (vector->stl-bytes v buf start) (real->floating-point-bytes (vec3-x v) 4 #f buf (+ start 0)) (real->floating-point-bytes (vec3-y v) 4 #f buf (+ start 4)) (real->floating-point-bytes (vec3-z v) 4 #f buf (+ start 8)))
false
cb923428e28c1eb803e84d07b11a4d891d539a0d
7e15b782f874bcc4192c668a12db901081a9248e
/eopl/ch1/ex-1.35.rkt
c054f345117557b5fbd9f9a2205810a730a621f7
[]
no_license
Javran/Thinking-dumps
5e392fe4a5c0580dc9b0c40ab9e5a09dad381863
bfb0639c81078602e4b57d9dd89abd17fce0491f
refs/heads/master
2021-05-22T11:29:02.579363
2021-04-20T18:04:20
2021-04-20T18:04:20
7,418,999
19
4
null
null
null
null
UTF-8
Racket
false
false
3,349
rkt
ex-1.35.rkt
#lang eopl (require "../common.rkt") ; leaf :: Int -> Bintree ; usage: create a leaf Bintree (define (leaf x) (list 'leaf x)) ; interior-node :: (Sym, Bintree, Bintree) -> Bintree ; usage: create a non-leaf Bintree (define (interior-node x l r) (list 'interior x l r)) ; leaf? :: Bintree -> Bool ; usage: test if the Bintree is a leaf (define (leaf? t) (eq? 'leaf (car t))) ; lson :: Bintree -> Bintree ; usage: fetch the left son (define (lson x) (list-ref x 2)) ; rson :: Bintree -> Bintree ; usage: fetch the right son (define (rson x) (list-ref x 3)) ; contents-of :: Bintree -> Either Sym Int ; usage: fetch the content from Bintree `x` (define (contents-of x) (list-ref x 1)) ; bintree->string :: Bintree -> String ; usage: convert Bintree to its string representation (define (bintree->string tree) (if (leaf? tree) (number->string (contents-of tree)) (string-append "(" (symbol->string (contents-of tree)) " " (bintree->string (lson tree)) " " (bintree->string (rson tree)) ")"))) ; number-leaves1 :: Bintree -> Bintree ; usage: replace all leaves with increasing numbers, starting from 0 (define (number-leaves1 tree) ; continuation approach (define (number-leaves-cont tree start-num cont) (if (leaf? tree) ; call continuation with created tree and the next `start-num` (cont (leaf start-num) (+ start-num 1)) ; build left tree (number-leaves-cont (lson tree) start-num (lambda (lson-done cur-num) ; build right tree (number-leaves-cont (rson tree) cur-num (lambda (rson-done cur-num) ; call contiuation with built tree (cont (interior-node (contents-of tree) lson-done rson-done) cur-num))))))) (number-leaves-cont tree 0 ; fetch result (lambda (c num) c))) ; number-leaves2 :: Bintree -> Bintree ; usage: replace all leaves with increasing numbers, starting from 0 (define (number-leaves2 tree) ; return a pair: (tree, next-num) (define (number-leaves-aux tree start-num) (if (leaf? tree) (cons (leaf start-num) (+ 1 start-num)) (let* ((lresult (number-leaves-aux (lson tree) start-num)) (rresult (number-leaves-aux (rson tree) (cdr lresult)))) (cons (interior-node (contents-of tree) (car lresult) (car rresult)) (cdr rresult))))) (car (number-leaves-aux tree 0))) (let ((tree1 (interior-node 'foo (interior-node 'bar (leaf 26) (leaf 12)) (interior-node 'baz (leaf 11) (interior-node 'quux (leaf 117) (leaf 14))))) (tree2 (interior-node 'a (leaf 20) (interior-node 'b (interior-node 'c (leaf 50) (leaf 60)) (leaf 40))))) (out (bintree->string (number-leaves1 tree1)) (bintree->string (number-leaves2 tree1)) (bintree->string (number-leaves1 tree2)) (bintree->string (number-leaves2 tree2)) ))
false
329aec1d6dc9c36fa46b60f1433d7501a699a377
e4d80c9d469c9ca9ea464a4ad213585a578d42bc
/lib/standards-csv-api.rkt
476a65e959df867c00b0ed173a34190bd9fcca64
[]
no_license
garciazz/curr
0244b95086b0a34d78f720e9cae1cb0fdb686ec5
589a93c4a43967b06d7a6ab9d476b470366f9323
refs/heads/master
2021-01-17T19:14:21.756115
2016-02-24T22:16:26
2016-02-24T22:16:26
53,657,555
1
0
null
2016-03-11T09:58:01
2016-03-11T09:58:01
null
UTF-8
Racket
false
false
9,042
rkt
standards-csv-api.rkt
#lang racket ;; API to extract standards/objectives/evidence data from spreadsheet (require (planet neil/csv:1:=7) ; csv library racket/runtime-path "paths.rkt" ; needed while we load the standards from csv file ) (provide get-standard-descr get-learnobj-tree get-evid-statement/tag get-evid-summary get-used-evidnums/std ) ;; location of the standards csv file (must be a path) (define-runtime-path lib-path (build-path 'up "lib")) (define STDS-CSV-FILE (build-path lib-path "standards.csv")) (define STDS-GDRIVE-SOURCE "https://docs.google.com/spreadsheet/ccc?key=0AjzMl1BJlJDkdFRkR0RRRUJqa21oZHJ3WEhHWE1IVHc&usp=sharing#gid=0") ;;;;; STANDARDS TREE DATA DEFN ;;;;;;;;;;;;;;;;;;;;;;;;; ;; (make-standard string string list[learnobj]) (define-struct standard (tag descr learnobjs)) ;; (make-learnobj (number string list[evidstmt]) (define-struct learnobj (id descr evidence)) ;; (make-evidstmt (number string string)) (define-struct evidstmt (id descr coverage)) ;; the standardslist is a list of standards ;;;;; CSV TO STANDARDS TREE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; The csv file has four columns: a tag (combining standard and objective label), ;; a description of the objective, the evidence statements, and whether or not ;; we claim to cover the objective. ;; ;; The original design of these data structures separated the standard and the ;; objective. The description of each standard will now be taken from the ;; single learning objective per tag (thus we will have replication between the ;; standard description and the learning objective. Might want to rewrite later ;; but duplication preserves the rest of the code for now. (define (read-csv filename) (call-with-input-file filename (lambda (p) (csv->list (make-csv-reader p '((separator-chars #\,))))))) (define csv-raw (read-csv STDS-CSV-FILE)) (define (cluster-lines-by-firstcol csvlist) (let loop ([unprocessed csvlist] [currstd empty] [finishedstds empty]) (if (empty? unprocessed) ;; include currstd in finishedstds list (append finishedstds (list currstd)) (cond [(string=? "" (caar unprocessed)) ;; line still part of currstd (loop (rest unprocessed) (append currstd (list (first unprocessed))) finishedstds)] [else ;; current line starts a new standard; archive previous and start new one (loop (rest unprocessed) (list (first unprocessed)) (if (empty? currstd) ;; base-case -- processing first standard empty (append finishedstds (list currstd))))])))) ;; takes strings of form "num. text" and decomposes into two ;; values, one for number and one for text. If string ;; doesn't have that form, returns #f and the original string (define (extract-id-descr str) (let ([labeled? (regexp-match #rx"([0-9]+)\\.(.*)" str)]) (if labeled? (values (string->number (second labeled?)) (third labeled?)) (values #f str)))) ;; converts the csv contents (as a list) into a tree of standards, ;; learning objectives, and evidence statements. Need to refine ;; once KF and ES agree on the spreadsheet format (define (csvlist-to-standards-tree csvlist) (let ([clusters (cluster-lines-by-firstcol csvlist)]) (map (lambda (cluster) (make-standard (caar cluster) (cadar cluster) (map (lambda (learnobj-cluster) (let-values ([(id descr) (extract-id-descr (caar learnobj-cluster))]) (make-learnobj id descr (map (lambda (evstr coveragestr) (let-values ([(id descr) (extract-id-descr evstr)]) (make-evidstmt id descr coveragestr))) (map second learnobj-cluster) (map third learnobj-cluster))))) (cluster-lines-by-firstcol (map cdr cluster))))) clusters))) ;; use rest to strip out the header line on the spreadsheet (define standards-tree (csvlist-to-standards-tree (rest csv-raw))) ;;;;; EXTRACT DATA FROM TREE ;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (find-std/tag tag) (let ([matches (filter (lambda (std) (string=? tag (standard-tag std))) standards-tree)]) (if (empty? matches) (printf (format "WARNING: find-std/tag finds no standard for tag ~a~n" tag)) (first matches)))) ;; given a standard id-tag, extract the description string for that id (define (get-standard-descr tag) (let ([std (find-std/tag tag)]) (if (void? std) #f (standard-descr std)))) ;; determine whether evidence statement is considered covered versus a list of coverage tags ;; uses string-trim to protect against whitespace in spreadsheet values (define (evid-covered-by taglist) (lambda (e) (member (string-trim (evidstmt-coverage e)) taglist))) ;; return list of descriptions of all covered evidence statements (define (get-evidence-descrs/coverage evidstmtlst coverage-tags) (map evidstmt-descr (filter (evid-covered-by coverage-tags) evidstmtlst))) ;; given standard id-tag, produce list of ((lobj (evidence ...) tag) ...) for that standard ;; optionally include tag name with lobj name (reasonable since spreadsheet conflates std and lobj) (define (get-learnobj-tree std-tag #:include-tag [include-tag? #t] #:with-coverage [with-coverage (list "Y" "N")]) (let* ([std (find-std/tag std-tag)] [lobjs (if (void? std) '() (standard-learnobjs std))]) (map (lambda (lobj) (list ;std-tag (learnobj-descr lobj) ;(if include-tag? ; (format "~a: ~a" std-tag (learnobj-descr lobj)) ; (learnobj-descr lobj)) (get-evidence-descrs/coverage (learnobj-evidence lobj) with-coverage) std-tag)) lobjs))) ;; returns evidence statement for given std string and numeric labels for ;; learning objective and evidence statement (define (get-evid-statement std learnindex evidindex) (let ([report-problem (lambda (msg) (printf "WARNING: get-evid-stmt: ~a~n" msg) #f)] [lotree (get-learnobj-tree std)]) (cond [(empty? lotree) #f] ;; if this happens, find-std/tag already reported unknown standard error [(not lotree) (report-problem (format "no learning objectives for standard ~a" std))] [(or (< learnindex 1) (> learnindex (length lotree))) (report-problem (format "no learning objective with index ~a for standard ~a" learnindex std))] [(or (< evidindex 1) (> evidindex (length (second (list-ref lotree (sub1 learnindex)))))) (report-problem (format "no evidence statement with index ~a for standard ~a and objective ~a" evidindex std learnindex))] [else (list-ref (second (list-ref lotree (sub1 learnindex))) (sub1 evidindex))]))) (define (get-evid-statement/tag evidtag) (let-values ([(std lonum esnum) (evidtag-data evidtag)]) (if (not (or std lonum esnum)) #f (get-evid-statement std lonum esnum)))) ;; the evidence tag list is coming in quoted, so need to remove the leading operator ;; if it is there. Current operator name is "exercise-evid-tags", as defined ;; in the macros for parsing solutions in lang.rkt (define (get-evid-summary evidtag) (if (list? evidtag) (map get-evid-statement/tag (if (memq (first evidtag) '(exercise-evid-tags)) (rest evidtag) evidtag)) (get-evid-statement/tag evidtag))) ;; an evidence tag has the form std&learnobj&evid, where learnobj and evid are numbers (define evidtag-regexp #rx"(.+)&([0-9]+)&([0-9]+)") ;; returns values for the standard, learning objective number, and evidence number from a tag ;; if the given string has the wrong format, returns #f (define (evidtag-data evidtagstr) (let ([data (regexp-match evidtag-regexp evidtagstr)]) (if data (values (second data) (string->number (third data)) (string->number (fourth data))) (begin (printf "WARNING: malformed evidence tag ~a~n" evidtagstr) (values #f #f #f))))) ;; given standard tag and a list of evidence tag, return list of indices of those in evid-used ;; ASSUMES only one learning objective per standard (define (get-used-evidnums/std stdtag evid-used) (remove-duplicates (foldr (lambda (evidtagstr result-rest) (let-values ([(evidstd lo evidnum) (evidtag-data evidtagstr)]) (if (equal? evidstd stdtag) (cons evidnum result-rest) result-rest))) '() evid-used))) ;;;;; ATTIC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; convert master spreadsheet to csv ;(system (format "cscript xls2csv.vbs ~a ~a" MASTER-SPREADSHEET MASTER-CSV)) ;(define MASTER-CSVLIST (make-parameter #f))
false
dd147c43a2dd0d769d12034513575b23d34b8bab
55ab4a7d38bb68c4690286aa70a10f12745bca0f
/exercises/129.rkt
bfcf692741db1fecf2e0acc8ce4f238a9551723d
[]
no_license
E-Neo/eopl
57e3cfac61be2885304531ab014f90a38233d37c
980410b29ec7571ce0c1f8abea7b50afc2edae31
refs/heads/main
2022-09-12T13:59:27.461039
2022-07-29T15:50:00
2022-07-29T15:50:00
119,218,596
3
2
null
null
null
null
UTF-8
Racket
false
false
1,014
rkt
129.rkt
#lang eopl ;; sort : Listof(Int) -> Listof(Int) ;; usage: (sort loi) returns a list of the elements of loi in ascending order. (define sort (lambda (loi) (if (< (length loi) 2) loi (let ((mid (quotient (length loi) 2))) (merge (sort (list-head loi mid)) (sort (list-tail loi mid))))))) ;; list-head : Listof(Int) -> Listof(Int) (define list-head (lambda (loi n) (if (zero? n) '() (append (list (car loi)) (list-head (cdr loi) (- n 1)))))) ;; merge : Listof(Int) * Listof(Int) -> Listof(Int) ;; usage: (merge loi1 loi2), where loi1 and loi2 are lists of integers that are ;; sorted in ascending order, returns a sorted list of all the integers ;; in loi1 and loi2. (define merge (lambda (loi1 loi2) (cond ((null? loi1) loi2) ((null? loi2) loi1) ((< (car loi2) (car loi1)) (cons (car loi2) (merge loi1 (cdr loi2)))) (else (cons (car loi1) (merge (cdr loi1) loi2))))))
false
b12c0ccb179ef3ab6f20bdad3702d0d56bb65279
926da98296a055016a3bb8cc0c26e7b1fcfb4078
/riottest/compoundwords.rkt
6db9b347c5eec9a6f1884df5a11d589b1bdf2c15
[]
no_license
wfi/puzzle-solver
8f41bfa6ab53e49cc0f98a5f2a416f9a3edba061
0db639007651a3ba8d0c089293778cdb558509f6
refs/heads/master
2021-01-17T01:18:59.526885
2017-09-11T18:13:38
2017-09-11T18:13:38
10,537,992
0
0
null
2016-08-28T05:24:10
2013-06-06T22:42:06
Racket
UTF-8
Racket
false
false
2,258
rkt
compoundwords.rkt
#lang racket ;; compoundwords.rkt (require (planet gcr/riot)) (define dictionary ;; create the set of dictionary words (for/set ([word (in-list (file->lines "evenfewerwords"))] #:when (>= (string-length word) 3)) word)) ;; package-dict: (listof string) -> (listof (listof string)) ;; turn the list of words into a list of package-sized lists of words (define (package-dict a-dict-list package-size) (cond [(empty? a-dict-list) empty] [(< (length a-dict-list) package-size) (list a-dict-list)] [else (cons (take a-dict-list package-size) (package-dict (drop a-dict-list package-size) package-size))])) (define (slow-combinations) (define local-dict (for/set ([word (in-list (file->lines "evenfewerwords"))] #:when (>= (string-length word) 3)) word)) (apply append (for/work ([bunch-of-words (in-list (package-dict (set->list local-dict) 3000))]) (apply append (for/list ([first-word (in-list bunch-of-words)]) (for/list ([second-word (in-set local-dict)] #:when (set-member? local-dict (string-append first-word second-word))) (cons first-word second-word))))))) (define (word-combinations) (apply append (for/work ([bunch-of-words (in-list (package-dict (set->list dictionary) 200))]) (apply append (for/list ([first-word (in-list bunch-of-words)]) (for/list ([second-word (in-set dictionary)] #:when (set-member? dictionary (string-append first-word second-word))) (cons first-word second-word))))))) (module+ main (connect-to-riot-server! "localhost") (define words (time (slow-combinations))) ;;(define words (time (word-combinations))) (printf "There are ~a compound-words in the dictionary.\n" (length words)) ;; Print a random subset of results (write (take (shuffle words) 20)) (newline))
false
e9d29e7e17e9b4faa7cb6080a936a0f6c65fa8be
e553691752e4d43e92c0818e2043234e7a61c01b
/test/query/synthax.rkt
f55545c0a950120f30e5804157fd19aa172ebfc0
[ "BSD-2-Clause" ]
permissive
emina/rosette
2b8c1bcf0bf744ba01ac41049a00b21d1d5d929f
5dd348906d8bafacef6354c2e5e75a67be0bec66
refs/heads/master
2023-08-30T20:16:51.221490
2023-08-11T01:38:48
2023-08-11T01:38:48
22,478,354
656
89
NOASSERTION
2023-09-14T02:27:51
2014-07-31T17:29:18
Racket
UTF-8
Racket
false
false
12,516
rkt
synthax.rkt
#lang rosette (require rackunit rackunit/text-ui rosette/lib/roseunit rosette/lib/synthax "synthax-external.rkt") (define-symbolic x y integer?) (define-synthax (rec x k) (assert (>= k 0)) (choose x (??) (+ x (rec x (sub1 k))))) (define (h0) (??)) (define (h1 x) (choose 1 (choose x 3))) (define (h2 x) (choose 6 (+ x (h0)) 8)) (define (h3 x) (choose 1 (h2 x))) (define-synthax (h4) (choose 1 2)) (define (h5) (h4)) (define (h6 x) (choose (??) (+ x (h5)))) (define (r1 x) (rec x 0)) (define (r2 x) (rec x 1)) (define (r3 x) (rec x 2)) (define (m1 x) (choose 1 (c2 x))) (define (m2 x) (crec x 0)) (define (m3 x) (crec x 2)) (define (m4 x)(crec (h1 x) 1)) (define-synthax (s0 x k) (assert (>= k 0)) (choose x (+ (choose 0 1) (s0 x (sub1 k))))) (define (s1) (choose 1 2)) (define-synthax (s2 x k) (assert (>= k 0)) (choose x (+ (s1) (s2 x (sub1 k))))) (define-synthax (s3) (choose 0 1)) (define-synthax (s4 x k) (assert (>= k 0)) (choose x (+ (s3) (s4 x (sub1 k))))) (define (f0 x) (s0 x 3)) (define (f1 x) (s2 x 3)) (define (f2 x) (s4 x 5)) (define-synthax (add-one z depth) (assert (>= depth 0)) (choose z (+ 1 (add-one-more z (- depth 1))))) (define-synthax (add-one-more y depth) (assert (>= depth 0)) (choose y (+ 1 (add-one y (- depth 1))))) (define (mutually-recursive x) (add-one x 3)) (define-namespace-anchor tests) (define ns (namespace-anchor->namespace tests)) (define (verified-equal? vars impl spec) (or (equal? impl spec) (begin (match-define `(,_ ... (define ,spec-h ,_ ...)) spec) (define consts (take (map term->datum vars) (sub1 (length spec-h)))) (define body `(let ([impl (lambda ,(cdr spec-h) ,@impl ,spec-h)] [spec (lambda ,(cdr spec-h) ,@spec ,spec-h)]) (unsat? (verify (assert (equal? (impl ,@consts) (spec ,@consts))))))) (eval body ns)))) (define-syntax-rule (check-synth vars expr expected) (let* ([vs (symbolics vars)] [sol (synthesize #:forall vs #:guarantee (assert expr))]) (check-sat sol) (check-true (verified-equal? vs (map syntax->datum (generate-forms sol)) expected)))) (define basic-tests (test-suite+ "Basic hole tests." (check-synth x (= (+ 2 x) (+ (h0) x)) '((define (h0) 2))) (check-synth x (= x (h1 x)) '((define (h1 x) x))) (check-synth x (= (* 2 x) (+ (h1 x) (h1 x))) '((define (h1 x) x))) (check-synth x (= (+ 2 x) (h3 x)) '((define (h0) 2) (define (h2 x) (+ x (h0))) (define (h3 x) (h2 x)))) (check-synth x (= (+ x 1) (h6 x)) '((define (h5) (let () 1)) (define (h6 x) (+ x (h5))))))) (define recursive-hole-tests (test-suite+ "Tests for recursive holes." (check-unsat (synthesize #:forall x #:guarantee (assert (= (* 2 x) (r1 x))))) (check-synth x (= -1 (r1 x)) '((define (r1 x) (let ((x x) (k 0)) (assert (>= k 0)) -1)))) (check-synth x (= -1 (r2 x)) '((define (r2 x) (let ((x x) (k 1)) (assert (>= k 0)) -1)))) (check-synth x (= -1 (r3 x)) '((define (r3 x) (let ((x x) (k 2)) (assert (>= k 0)) -1)))) (check-synth x (= x (r1 x)) '((define (r1 x) (let ((x x) (k 0)) (assert (>= k 0)) x)))) (check-synth x (= (add1 x) (r2 x)) '((define (r2 x) (let ((x x) (k 1)) (assert (>= k 0)) (+ x (let ((x x) (k (sub1 k))) (assert (>= k 0)) 1)))))) (check-unsat (synthesize #:forall x #:guarantee (assert (= (* 3 x) (r2 x))))) (check-synth x (= (* 3 x) (r3 x)) '((define (r3 x) (let ((x x) (k 2)) (assert (>= k 0)) (+ x (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ x (let ((x x) (k (sub1 k))) (assert (>= k 0)) x)))))))) (check-synth x (= (+ x 3) (mutually-recursive x)) '((define (mutually-recursive x) (let ((z x) (depth 3)) (assert (>= depth 0)) (+ 1 (let ((y z) (depth (- depth 1))) (assert (>= depth 0)) (+ 1 (let ((z y) (depth (- depth 1))) (assert (>= depth 0)) (+ 1 (let ((y z) (depth (- depth 1))) (assert (>= depth 0)) y)))))))))))) (define imported-hole-tests (test-suite+ "Tests that use holes defined in imported modules." (check-synth x (= (+ 2 x) (+ (c0) x)) '((define (c0) 2))) (check-synth x (= (* 2 x) (+ (c1 x) (c1 x))) '((define (c1 x) x))) (check-synth x (= (+ 2 x) (c3 x)) '((define (c0) 2) (define (c2 x) (+ x (c0))) (define (c3 x) (c2 x)))) (check-synth x (= (+ 2 x) (m1 x)) '((define (c0) 2) (define (c2 x) (+ x (c0))) (define (m1 x) (c2 x)))) (check-synth x (= -1 (m2 x)) '((define (c0) -1) (define (m2 x) (let ((x x) (k 0)) (assert (>= k 0)) (c0))))) (check-synth x (= -1 (m3 x)) '((define (c0) -1) (define (m3 x) (let ((x x) (k 2)) (assert (>= k 0)) (c0))))) (check-synth x (= (+ x 2) (m4 x)) '((define (c0) 2) (define (h1 x) x) (define (m4 x) (let ((x (h1 x)) (k 1)) (assert (>= k 0)) (+ x (let ((x x) (k (sub1 k))) (assert (>= k 0)) (c0))))))))) (define stress-tests (test-suite+ "Stress tests for recursive holes." (check-synth x (= (+ x 3) (f0 x)) '((define (f0 x) (let ((x x) (k 3)) (assert (>= k 0)) (+ 1 (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ 1 (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ 1 (let ((x x) (k (sub1 k))) (assert (>= k 0)) x)))))))))) (check-synth x (= (+ x 3) (f1 x)) '((define (s1) 1) (define (f1 x) (let ((x x) (k 3)) (assert (>= k 0)) (+ (s1) (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ (s1) (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ (s1) (let ((x x) (k (sub1 k))) (assert (>= k 0)) x)))))))))) (check-synth x (= (+ x 5) (f2 x)) '((define (f2 x) (let ((x x) (k 5)) (assert (>= k 0)) (+ (let () 1) (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ (let () 1) (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ (let () 1) (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ (let () 1) (let ((x x) (k (sub1 k))) (assert (>= k 0)) (+ (let () 1) (let ((x x) (k (sub1 k))) (assert (>= k 0)) x)))))))))))))))) (define-synthax (op left right) [choose (+ left right) (- left right)]) (define-synthax (idx tid step depth) (assert (>= depth 0)) (choose tid step (op (idx tid step (- depth 1)) (idx tid step (- depth 1))))) (define (cidx1 tid step) (idx tid step 1)) (define regression-tests (test-suite+ "Regression tests for synthax." (check-synth (list x y) (= x (cidx1 x y)) '((define (cidx1 tid step) (let ((tid tid) (step step) (depth 1)) (assert (>= depth 0)) tid)))) (check-synth (list x y) (= (+ x y) (cidx1 x y)) '((define (cidx1 tid step) (let ((tid tid) (step step) (depth 1)) (assert (>= depth 0)) (let ((left (let ((tid tid) (step step) (depth (- depth 1))) (assert (>= depth 0)) tid)) (right (let ((tid tid) (step step) (depth (- depth 1))) (assert (>= depth 0)) step))) (+ left right)))))))) (module+ test (time (run-tests basic-tests)) (time (run-tests recursive-hole-tests)) (time (run-tests imported-hole-tests)) (time (run-tests stress-tests)) (time (run-tests regression-tests)))
true
a48136d75791db67b5e09f40c19cf8ecd6a3718e
20a9cc2e1884f9e3e8f953ccd7b04e3e4c820f1a
/src/syntax/test-rules.rkt
62b52881e7cf3a794439dfd2e9001149d4cba68b
[ "MIT" ]
permissive
iCodeIN/herbie
741c2b10b821041c1d234b4c4ee7b57af47a7a3a
d3249e9721223fd6acc70f4a0d21b37f8e2ecfdc
refs/heads/master
2023-09-06T08:22:59.517664
2021-10-01T15:30:05
2021-10-01T15:30:05
null
0
0
null
null
null
null
UTF-8
Racket
false
false
4,824
rkt
test-rules.rkt
#lang racket (require rackunit math/bigfloat) (require "../common.rkt" "../programs.rkt" "../sampling.rkt" (submod "../points.rkt" internals)) (require "rules.rkt" (submod "rules.rkt" internals) "../interface.rkt") (require "../programs.rkt" "../float.rkt" "sugar.rkt" "../load-plugin.rkt") (load-herbie-builtins) (define num-test-points (make-parameter 100)) ;; WARNING: These aren't treated as preconditions, they are only used for range inference (define *conditions* `([asinh-2_binary64 . (>= x 0)] [asinh-2_binary32 . (>= x 0)] ;; These next three approximate pi so that range analysis will work [asin-sin-s_binary64 . (<= (fabs x) 1.5708)] [asin-sin-s_binary32 . (<= (fabs x) 1.5708)] [acos-cos-s_binary64 . (<= 0 x 3.1415)] [acos-cos-s_binary32 . (<= 0 x 3.1415)] [atan-tan-s_binary64 . (<= (fabs x) 1.5708)] [atan-tan-s_binary32 . (<= (fabs x) 1.5708)])) (define (ival-ground-truth fv p repr) (define prog (eval-prog `(λ ,fv ,p) 'ival repr)) (λ (x) (ival-eval prog x repr))) (define ((with-hiprec f) x) (parameterize ([bf-precision 2000]) (apply f x))) (define (bf-ground-truth fv p repr) (with-hiprec (compose (representation-bf->repr repr) (eval-prog `(λ ,fv ,p) 'bf repr)))) (define (check-rule-correct test-rule ground-truth) (match-define (rule name p1 p2 itypes repr) test-rule) (define fv (dict-keys itypes)) (*var-reprs* itypes) (define ival-bad? (conjoin real? nan?)) (define make-point (make-sampler repr `(λ ,fv ,(desugar-program (dict-ref *conditions* name '(TRUE)) repr (*var-reprs*))) `((λ ,fv ,p1) (λ ,fv ,p2)) empty)) (define points (for/list ([n (in-range (num-test-points))]) (make-point))) (define prog1 (ground-truth fv p1 repr)) (define prog2 (ground-truth fv p2 repr)) (define ex1 (map prog1 points)) (define ex2 (map prog2 points)) (define errs (for/list ([pt points] [v1 ex1] [v2 ex2] ;; Error code from ival-eval #:unless (or (ival-bad? v1) (ival-bad? v2)) ;; Ignore rules that compute to bad values #:when (and (ordinary-value? v1 repr) (ordinary-value? v2 repr))) (with-check-info (['point (map cons fv pt)] ['method (object-name ground-truth)] ['input v1] ['output v2]) (check-eq? (ulp-difference v1 v2 repr) 1)))) (define usable-fraction (/ (length errs) (num-test-points))) (cond [(< usable-fraction 1/10) (fail-check "Not enough points sampled to test rule")] [(< usable-fraction 8/10) (eprintf "~a: ~a% of points usable\n" name (~r (* 100 usable-fraction) #:precision '(= 0)))])) (define (check-rule-fp-safe test-rule) (match-define (rule name p1 p2 itypes repr) test-rule) (define fv (dict-keys itypes)) (*var-reprs* itypes) (define (make-point) (for/list ([v (in-list fv)]) (random-generate (dict-ref itypes v)))) (define point-sequence (in-producer make-point)) (define points (for/list ([n (in-range (num-test-points))] [pt point-sequence]) pt)) (define prog1 (eval-prog `(λ ,fv ,p1) 'fl repr)) (define prog2 (eval-prog `(λ ,fv ,p2) 'fl repr)) (define-values (ex1 ex2) (for/lists (ex1 ex2) ([pt points]) (values (apply prog1 pt) (apply prog2 pt)))) (for ([pt points] [v1 ex1] [v2 ex2]) (with-check-info (['point (map list fv pt)]) (match (representation-name repr) ;; TODO: Why is this here? ['binary32 (check-equal? (->float32 v1) (->float32 v2))] ; casting problems [else (check-equal? v1 v2)])))) (module+ main (*needed-reprs* (map get-representation '(binary64 binary32 bool))) (define _ (*simplify-rules*)) ; force an update (num-test-points (* 100 (num-test-points))) (command-line #:args names (for ([name names]) (eprintf "Checking ~a...\n" name) (define rule (first (filter (λ (x) (equal? (~a (rule-name x)) name)) (*rules*)))) (check-rule-correct rule ival-ground-truth) (when (set-member? (*fp-safe-simplify-rules*) rule) (check-rule-fp-safe rule))))) (module+ test (*needed-reprs* (map get-representation '(binary64 binary32 bool))) (define _ (*simplify-rules*)) ; force an update (for* ([test-ruleset (*rulesets*)] [test-rule (first test-ruleset)]) (unless (and (expr-supports? (rule-input test-rule) 'ival) (expr-supports? (rule-output test-rule) 'ival)) (fail-check "Rule does not support ival sampling")) (test-case (~a (rule-name test-rule)) (check-rule-correct test-rule ival-ground-truth))) (for* ([test-ruleset (*rulesets*)] [test-rule (first test-ruleset)] #:when (set-member? (*fp-safe-simplify-rules*) test-rule)) (test-case (~a (rule-name test-rule)) (check-rule-fp-safe test-rule))))
false
2553252a0161b29e5f196f4e324f7d51d0ca18a7
fc6465100ab657aa1e31af6a4ab77a3284c28ff0
/results/fair-24/stlc-sub-7-ordered.rktd
8a0a616f2fca2869094ae1a98923c4526257a80d
[]
no_license
maxsnew/Redex-Enum-Paper
f5ba64a34904beb6ed9be39ff9a5e1e5413c059b
d77ec860d138cb023628cc41f532dd4eb142f15b
refs/heads/master
2020-05-21T20:07:31.382540
2017-09-04T14:42:13
2017-09-04T14:42:13
17,602,325
0
0
null
null
null
null
UTF-8
Racket
false
false
2,149
rktd
stlc-sub-7-ordered.rktd
(start 2015-06-21T19:45:22 (#:model "stlc-sub-7" #:type ordered)) (gc-major 2015-06-21T19:45:23 (#:amount 23239400 #:time 304)) (heartbeat 2015-06-21T19:45:23 (#:model "stlc-sub-7" #:type ordered)) (gc-major 2015-06-21T19:45:23 (#:amount 402072 #:time 257)) (counterexample 2015-06-21T19:45:26 (#:model "stlc-sub-7" #:type ordered #:counterexample ((λ (b int) (λ (a int) a)) 0) #:iterations 4847 #:time 2833)) (new-average 2015-06-21T19:45:26 (#:model "stlc-sub-7" #:type ordered #:average 2832.0 #:stderr +nan.0)) (counterexample 2015-06-21T19:45:29 (#:model "stlc-sub-7" #:type ordered #:counterexample ((λ (b int) (λ (a int) a)) 0) #:iterations 4847 #:time 2776)) (new-average 2015-06-21T19:45:29 (#:model "stlc-sub-7" #:type ordered #:average 2803.5 #:stderr 28.499999999999996)) (counterexample 2015-06-21T19:45:31 (#:model "stlc-sub-7" #:type ordered #:counterexample ((λ (b int) (λ (a int) a)) 0) #:iterations 4847 #:time 2762)) (new-average 2015-06-21T19:45:31 (#:model "stlc-sub-7" #:type ordered #:average 2789.6666666666665 #:stderr 21.49676978318164)) (heartbeat 2015-06-21T19:45:33 (#:model "stlc-sub-7" #:type ordered)) (counterexample 2015-06-21T19:45:34 (#:model "stlc-sub-7" #:type ordered #:counterexample ((λ (b int) (λ (a int) a)) 0) #:iterations 4847 #:time 2854)) (new-average 2015-06-21T19:45:34 (#:model "stlc-sub-7" #:type ordered #:average 2805.75 #:stderr 22.129825274201057)) (counterexample 2015-06-21T19:45:37 (#:model "stlc-sub-7" #:type ordered #:counterexample ((λ (b int) (λ (a int) a)) 0) #:iterations 4847 #:time 2833)) (new-average 2015-06-21T19:45:37 (#:model "stlc-sub-7" #:type ordered #:average 2811.2 #:stderr 17.987217683677503)) (counterexample 2015-06-21T19:45:40 (#:model "stlc-sub-7" #:type ordered #:counterexample ((λ (b int) (λ (a int) a)) 0) #:iterations 4847 #:time 2841)) (new-average 2015-06-21T19:45:40 (#:model "stlc-sub-7" #:type ordered #:average 2816.1666666666665 #:stderr 15.503583815076821)) (finished 2015-06-21T19:45:40 (#:model "stlc-sub-7" #:type ordered #:time-ms 16902 #:attempts 29082 #:num-counterexamples 6 #:rate-terms/s 1720.6247781327654 #:attempts/cexp 4847.0))
false
244ce2d3b1520c28064b8244eb3005b94c702869
69737038eb05d67fc7e5f2a793dad960174cc913
/info.rkt
93ea8af53257428c0c019cf3b68d3fe2e73d2307
[ "MIT" ]
permissive
hoelzl/Iliad-Racket
c3265b77dd6793e84f3b24da290d56613d2aef97
b29e410662d9017f67a16292fb80639c7806ba07
refs/heads/master
2021-01-10T10:01:24.159725
2013-03-18T16:31:21
2013-03-18T16:31:21
8,446,223
0
1
null
null
null
null
UTF-8
Racket
false
false
44
rkt
info.rkt
#lang setup/infotab (define deps (list))
false
e628e6469003117f650e51b632c377e9120df779
d0d656b7729bd95d688e04be38dde7d8cde19d3d
/1/1.2/solution.1.09.rkt
40c1765e0a1ee506b0066c0840576289e426f88d
[ "MIT" ]
permissive
search-good-project/SICP-in-Racket
f0157335a1d39c8ff4231e579fc13b0297c07e65
daaae62db83bf8e911f4b8dbd00f8509113f557a
refs/heads/master
2022-02-20T01:21:33.633182
2019-09-16T03:58:02
2019-09-16T03:58:02
null
0
0
null
null
null
null
UTF-8
Racket
false
false
348
rkt
solution.1.09.rkt
#lang sicp ;这是递归的方式计算 (define (r+ a b) (display a) (display " ") (display b) (display "\n") (if (= a 0) b (inc (r+ (dec a) b)))) (r+ 4 5) ;这是迭代的方式计算 (define (i+ a b) (display a) (display " ") (display b) (display "\n") (if (= a 0) b (i+ (dec a) (inc b)))) (i+ 4 5)
false
dcb3c4fddd9a0ca2765af1341e27c1783be0f45e
a967a396b487ab4cff14bc4904fd9b82548cf909
/userauth.rkt
528f5eccf54ad1388a75acc6dd4883793b3cdd97
[]
no_license
tewk/racket-ssh
b7b4f054e834d35c2ca82368cf0f63b09dc23d26
cabace0660822bc2085848e7572b54b49702ff0c
refs/heads/master
2020-12-24T17:35:38.179287
2012-01-20T19:46:38
2012-01-20T19:46:38
3,229,106
1
0
null
null
null
null
UTF-8
Racket
false
false
3,464
rkt
userauth.rkt
#lang racket (require "utils.rkt") (require "constants.rkt") (require "ssh-openssl.rkt") (provide do-client-user-auth do-server-user-auth) (define (do-client-user-auth io sessionid #:user [user "tewk"] #:service [serv "ssh-connection"] #:keyfiles [keyfiles (list "/home/tewk/.ssh/tewk2010_2")]) (sendp io SSH_MSG_SERVICE_REQUEST "ssh-userauth") (unless (recv/assert io SSH_MSG_SERVICE_ACCEPT "ssh-userauth") (error 'do-client-user-auth "BAD USER AUTH SERVICE REQUEST")) (let loop ([keys keyfiles]) (match keys [(list) #f] [(list-rest head tail) (define privkey (fn->RSAPrivateKey head)) (define pubkey (ssh-public-key-file->RSAPublicKey (string-append head ".pub"))) (define pubkey-sshblob (RSAPublicKey->ssh_keyblob pubkey)) (define algo "ssh-rsa") (sendp io SSH_MSG_USERAUTH_REQUEST user serv "publickey" #f algo (build-ssh-bytes pubkey-sshblob)) (define-values (pktid in) (recv/in io "b")) (cond [(equal? pktid SSH_MSG_USERAUTH_PK_OK) (define local-sig (unparse "sbsssBss" sessionid SSH_MSG_USERAUTH_REQUEST user serv "publickey" #t algo pubkey-sshblob)) (define sig (sha1-rsa-sign/key local-sig privkey)) (sendp io SSH_MSG_USERAUTH_REQUEST user serv "publickey" #t algo (build-ssh-bytes pubkey-sshblob) (build-ssh-bytes (unparse "ss" "ssh-rsa" sig))) (define-values (pktid in) (recv/in io "b")) (cond [(equal? pktid SSH_MSG_USERAUTH_SUCCESS) #t] [(equal? pktid SSH_MSG_USERAUTH_FAILURE) (loop tail)] [else (error "Unexpected pktid ~a" pktid)])] [(equal? pktid SSH_MSG_USERAUTH_FAILURE) (loop tail)] [else (error "Unexpected pktid ~a" pktid)])]))) (define (auth-failure io others) (sendp io SSH_MSG_USERAUTH_FAILURE others #f) #f) (define (auth-success io) (sendp io SSH_MSG_USERAUTH_SUCCESS) #t) (define (parse-auth-request io sessionid) (define in (open-input-bytes (send io recv-packet))) (define-values (pktid user serv type) (parse in "bsss")) (cond [(bytes=? type #"publickey") (define-values (bool algo keyy) (parse in "Bss")) (if bool (let ([sign (read-ssh-string in)]) (define-values (key-alg key1 key2) (parse/bs keyy "sss")) (define-values (sig-alg sig) (parse/bs sign "ss")) (define local-sig (unparse "sbsssBss" sessionid SSH_MSG_USERAUTH_REQUEST user serv type bool algo keyy)) (define rc (sha1-rsa-verify/sha1/e_n local-sig key1 key2 sig)) (if (= rc 1) (auth-success io) (auth-failure io "publickey"))) (let () (sendp io SSH_MSG_USERAUTH_PK_OK (->sshb algo keyy)) (parse-auth-request io sessionid)))] [(bytes=? type #"none") (auth-failure io "publickey") (parse-auth-request io sessionid)] [(bytes=? type #"password") (define-values (bool pass) (parse in "Bs")) (if (equal? pass #"BOGUSBOGUS") (auth-success io) (auth-failure io ""))])) (define (do-server-user-auth io sessionid) (recv/assert io SSH_MSG_SERVICE_REQUEST "ssh-userauth") (sendp io SSH_MSG_SERVICE_ACCEPT "ssh-userauth") (parse-auth-request io sessionid))
false
67a7d0db2ae549645f63bc5dfbe719437e3d946e
6e2088c94931e0baea8e834203d3ccb478828335
/remora/dynamic.rkt
0b92c13807001e50a649e199bcdc048a2afb6d2c
[]
no_license
jrslepak/Remora
d5155a78b5c952a822ce65109d092bd6a27545ec
1a831dec554df9a7ef3eeb10f0d22036f1f86dbd
refs/heads/master
2020-04-05T14:35:48.257381
2020-03-24T18:18:34
2020-03-24T18:18:34
10,669,532
119
12
null
2016-09-02T13:48:11
2013-06-13T15:41:04
Racket
UTF-8
Racket
false
false
90
rkt
dynamic.rkt
#lang racket/base (require "dynamic/main.rkt") (provide (all-from-out "dynamic/main.rkt"))
false
8e41c98395fb3a6ba16584c3384719ae9665de6e
14be9e4cde12392ebc202e69ae87bbbedd2fea64
/CSC488/lecture/w1/w1.rkt
9ec4b5378e63113167258308d03849f621088f54
[ "LicenseRef-scancode-unknown-license-reference", "GLWTPL" ]
permissive
zijuzhang/Courses
948e9d0288a5f168b0d2dddfdf825b4ef4ef4e1e
71ab333bf34d105a33860fc2857ddd8dfbc8de07
refs/heads/master
2022-01-23T13:31:58.695290
2019-08-07T03:13:09
2019-08-07T03:13:09
null
0
0
null
null
null
null
UTF-8
Racket
false
false
1,204
rkt
w1.rkt
#lang racket ; ... is kleene-★, 0 or more of the previous thing ; Here. square brackets are for grouping ★descriptions★ #| def <name>(<parameter-name> [, <parameter-name>] ...): <statement> <statement> := if <expression>: <statement> else: <statement> | return <expression> <expression> := <expression> <op> <expression> | <expression>(<expression>, [, <expression>] ...) | <variable-name> | <number> <op> := + | - | <= | >= Above is context-free grammar, CFG. <statement> is a "non-terminal" <expression> ... + - <= >= |# #| Some <expression>s: 0 x x + 0 x + 0 + 0 (is it (x + 0) + 0 or x + (0 + 0)) x - y - z (more than 1 parsing) x(0) 0(0) |# ; Nanopass compiling (define (remove-sum c) (match c [`(sum ,e1 ,op ,e2) `(,op ,e1 ,e2)] [_ c])) ; rewrite rule (define (rewrite rule v) (define v′ (rule v)) (define v′′ (if (list? v′) (map (curry rewrite rule) #; (λ (x) (rewrite rule v)) v′) v′)) (if (equal? v v′′) v (rewrite rule v′′))) ; (rewrite remove-sum code)
false
613e07c0cf7a11c2a95df187dbe6c72b0ea3d2f3
1df52a4271384959754624ef1381615a7c1b543c
/database.en.rktd
e764da8ba01e892bcea64f6eb32f71adb475a8c9
[ "MIT" ]
permissive
dherman/nationality.rkt
bbfc6ce258958593df234b27efb70f513246ebda
2fe559a6aee6780fa607ee2edf19a58534a90055
refs/heads/master
2016-09-09T21:53:21.573874
2012-02-28T00:24:55
2012-02-28T00:24:55
3,563,543
0
1
null
null
null
null
UTF-8
Racket
false
false
25,743
rktd
database.en.rktd
(("Afghanistan" (noun (singular . "Afghan") (plural . "Afghans")) (adjective (* . "Afghan"))) ("Akrotiri" . #f) ("Albania" (noun (singular . "Albanian") (plural . "Albanians")) (adjective (* . "Albanian"))) ("Algeria" (noun (singular . "Algerian") (plural . "Algerians")) (adjective (* . "Algerian"))) ("American Samoa" (noun (singular . "American Samoan") (plural . "American Samoans")) (adjective (* . "American Samoan"))) ("Andorra" (noun (singular . "Andorran") (plural . "Andorrans")) (adjective (* . "Andorran"))) ("Angola" (noun (singular . "Angolan") (plural . "Angolans")) (adjective (* . "Angolan"))) ("Anguilla" (noun (singular . "Anguillan") (plural . "Anguillans")) (adjective (* . "Anguillan"))) ("Antarctica" . #f) ("Antigua" (noun (singular . "Antiguan") (plural . "Antiguans")) (adjective (* . "Antiguan"))) ("Argentina" (noun (singular . "Argentine") (plural . "Argentines")) (adjective (* . "Argentine"))) ("Armenia" (noun (singular . "Armenian") (plural . "Armenians")) (adjective (* . "Armenian"))) ("Aruba" (noun (singular . "Aruban") (plural . "Arubans")) (adjective (* . "Aruban"))) ("Ashmore and Cartier Islands" . #f) ("Australia" (noun (singular . "Australian") (plural . "Australians")) (adjective (* . "Australian"))) ("Austria" (noun (singular . "Austrian") (plural . "Austrians")) (adjective (* . "Austrian"))) ("Azerbaijan" (noun (singular . "Azerbaijani") (plural . "Azerbaijanis")) (adjective (* . "Azerbaijani"))) ("Bahamas, The" (noun (singular . "Bahamian") (plural . "Bahamians")) (adjective (* . "Bahamian"))) ("Bahrain" (noun (singular . "Bahraini") (plural . "Bahrainis")) (adjective (* . "Bahraini"))) ("Baker Island" . #f) ("Bangladesh" (noun (singular . "Bangladeshi") (plural . "Bangladeshis")) (adjective (* . "Bangladeshi"))) ("Barbados" (noun (singular . "Barbadian") (plural . "Barbadians") (colloquial . "Bajan")) (adjective (* . "Barbadian") (colloquial . "Bajan"))) ("Barbuda" (noun (singular . "Barbudan") (plural . "Barbudans")) (adjective (* . "Barbudan"))) ("Bassas da India" . #f) ("Belarus" (noun (singular . "Belarusian") (plural . "Belarusians")) (adjective (* . "Belarusian"))) ("Belgium" (noun (singular . "Belgian") (plural . "Belgians")) (adjective (* . "Belgian"))) ("Belize" (noun (singular . "Belizean") (plural . "Belizeans")) (adjective (* . "Belizean"))) ("Benin" (noun (singular . "Beninese") (plural . "Beninese")) (adjective (* . "Beninese"))) ("Bermuda" (noun (singular . "Bermudian") (plural . "Bermudians")) (adjective (* . "Bermudian"))) ("Bhutan" (noun (singular . "Bhutanese") (plural . "Bhutanese")) (adjective (* . "Bhutanese"))) ("Bolivia" (noun (singular . "Bolivian") (plural . "Bolivians")) (adjective (* . "Bolivian"))) ("Bosnia" (noun (singular . "Bosnian") (plural . "Bosnians")) (adjective (* . "Bosnian"))) ("Botswana" (noun (singular . "Motswana") (plural . "Batswana")) (adjective (singular . "Motswana") (plural . "Batswana"))) ("Bouvet Island" . #f) ("Brazil" (noun (singular . "Brazilian") (plural . "Brazilians")) (adjective (* . "Brazilian"))) ("British Indian Ocean Territory" . #f) ("British Virgin Islands, The" (noun (singular . "British Virgin Islander") (plural . "British Virgin Islanders")) (adjective (* . "British Virgin Islander"))) ("Brunei" (noun (singular . "Bruneian") (plural . "Bruneians")) (adjective (* . "Bruneian"))) ("Bulgaria" (noun (singular . "Bulgarian") (plural . "Bulgarians")) (adjective (* . "Bulgarian"))) ("Burkina Faso" (noun (singular . "Burkinabe") (plural . "Burkinabe")) (adjective (* . "Burkinabe"))) ("Burma" (noun (singular . "Burmese") (plural . "Burmese")) (adjective (* . "Burmese"))) ("Burundi" (noun (singular . "Burundian") (plural . "Burundians")) (adjective (* . "Burundian"))) ("Cambodia" (noun (singular . "Cambodian") (plural . "Cambodians")) (adjective (* . "Cambodian"))) ("Cameroon" (noun (singular . "Cameroonian") (plural . "Cameroonians")) (adjective (* . "Cameroonian"))) ("Canada" (noun (singular . "Canadian") (plural . "Canadians")) (adjective (* . "Canadian"))) ("Cape Verde" (noun (singular . "Cape Verdean") (plural . "Cape Verdeans")) (adjective (* . "Cape Verdean"))) ("Cayman Islands, The" (noun (singular . "Caymanian") (plural . "Caymanians")) (adjective (* . "Caymanian"))) ("Central African Republic, The" (noun (singular . "Central African") (plural . "Central Africans")) (adjective (* . "Central African"))) ("Chad" (noun (singular . "Chadian") (plural . "Chadians")) (adjective (* . "Chadian"))) ("Chile" (noun (singular . "Chilean") (plural . "Chileans")) (adjective (* . "Chilean"))) ("China" (noun (singular . "Chinese") (plural . "Chinese")) (adjective (* . "Chinese"))) ("Christmas Island" (noun (singular . "Christmas Islander") (plural . "Christmas Islanders")) (adjective (* . "Christmas Island"))) ("Clipperton Island" . #f) ("Cocos (Keeling) Islands, The" (noun (singular . "Cocos Islander") (plural . "Cocos Islanders")) (adjective (* . "Cocos Islander"))) ("Colombia" (noun (singular . "Colombian") (plural . "Colombians")) (adjective (* . "Colombian"))) ("Comoros" (noun (singular . "Comoran") (plural . "Comorans")) (adjective (* . "Comoran"))) ("Congo, The Democratic Republic of the" (noun (singular . "Congolese") (plural . "Congolese")) (adjective (* . "Congolese"))) ("Congo, The Republic of the" (noun (singular . "Congolese") (plural . "Congolese")) (adjective (* . "Congolese"))) ("Cook Islands, The" (noun (singular . "Cook Islander") (plural . "Cook Islanders")) (adjective (* . "Cook Islander"))) ("Coral Sea Islands, The" . #f) ("Costa Rica" (noun (singular . "Costa Rican") (plural . "Costa Ricans")) (adjective (* . "Costa Rican"))) ("Cote d'Ivoire" (noun (singular . "Ivoirian") (plural . "Ivoirians")) (adjective (* . "Ivoirian"))) ("Croatia" (noun (singular . "Croat") (plural . "Croats")) (adjective (* . "Croatian"))) ("Cuba" (noun (singular . "Cuban") (plural . "Cubans")) (adjective (* . "Cuban"))) ("Cyprus" (noun (singular . "Cypriot") (plural . "Cypriots")) (adjective (* . "Cypriot"))) ("Czech Republic, The" (noun (singular . "Czech") (plural . "Czechs")) (adjective (* . "Czech"))) ("Denmark" (noun (singular . "Dane") (plural . "Danes")) (adjective (* . "Danish"))) ("Dhekelia" . #f) ("Djibouti" (noun (singular . "Djiboutian") (plural . "Djiboutians")) (adjective (* . "Djiboutian"))) ("Dominica" (noun (singular . "Dominican") (plural . "Dominicans")) (adjective (* . "Dominican"))) ("Dominican Republic, The" (noun (singular . "Dominican") (plural . "Dominicans")) (adjective (* . "Dominican"))) ("East Timor" (noun (* . "Timorese")) (adjective (* . "Timorese"))) ("Ecuador" (noun (singular . "Ecuadorian") (plural . "Ecuadorians")) (adjective (* . "Ecuadorian"))) ("Egypt" (noun (singular . "Egyptian") (plural . "Egyptians")) (adjective (* . "Egyptian"))) ("El Salvador" (noun (singular . "Salvadoran") (plural . "Salvadorans")) (adjective (* . "Salvadoran"))) ("England" (noun (masculine . "Frenchman") (feminine . "Frenchwoman") (plural . "English")) (adjective (* . "English"))) ("Equatorial Guinea" (noun (singular . "Equatorial Guinean") (plural . "Equatorial Guineans")) (adjective (* . "Equatorial Guinean"))) ("Eritrea" (noun (singular . "Eritrean") (plural . "Eritreans")) (adjective (* . "Eritrean"))) ("Estonia" (noun (singular . "Estonian") (plural . "Estonians")) (adjective (* . "Estonian"))) ("Ethiopia" (noun (singular . "Ethiopian") (plural . "Ethiopians")) (adjective (* . "Ethiopian"))) ("Europa Island" . #f) ("Falkland Islands (Islas Malvinas), The" (noun (singular . "Falkland Islander") (plural . "Falkland Islanders")) (adjective (* . "Falkland Island"))) ("Faroe Islands, The" (noun (singular . "Faroese") (plural . "Faroese")) (adjective (* . "Faroese"))) ("Fiji" (noun (singular . "Fijian") (plural . "Fijians")) (adjective (* . "Fijian"))) ("Finland" (noun (singular . "Finn") (plural . "Finns")) (adjective (* . "Finnish"))) ("France" (noun (masculine . "Frenchman") (feminine . "Frenchwoman") (plural . "French")) (adjective (* . "French"))) ("French Guiana" (noun (singular . "French Guianese") (plural . "French Guianese")) (adjective (* . "French Guianese"))) ("French Polynesia" (noun (singular . "French Polynesian") (plural . "French Polynesians")) (adjective (* . "French Polynesian"))) ("French Southern and Antarctic Lands" . #f) ("Gabon" (noun (singular . "Gabonese") (plural . "Gabonese")) (adjective (* . "Gabonese"))) ("Gambia, The" (noun (singular . "Gambian") (plural . "Gambians")) (adjective (* . "Gambian"))) ("Georgia" (noun (singular . "Georgian") (plural . "Georgians")) (adjective (* . "Georgian"))) ("Germany" (noun (singular . "German") (plural . "Germans")) (adjective (* . "German"))) ("Ghana" (noun (singular . "Ghanaian") (plural . "Ghanaians")) (adjective (* . "Ghanaian"))) ("Gibraltar" (noun (singular . "Gibraltarian") (plural . "Gibraltarians")) (adjective (* . "Gibraltar"))) ("Glorioso Islands, The" . #f) ("Greece" (noun (singular . "Greek") (plural . "Greeks")) (adjective (* . "Greek"))) ("Greenland" (noun (singular . "Greenlander") (plural . "Greenlanders")) (adjective (* . "Greenlandic"))) ("Grenada" (noun (singular . "Grenadian") (plural . "Grenadians")) (adjective (* . "Grenadian"))) ("Guadeloupe" (noun (singular . "Guadeloupian") (plural . "Guadeloupians")) (adjective (* . "Guadeloupe"))) ("Guam" (noun (singular . "Guamanian") (plural . "Guamanians")) (adjective (* . "Guamanian"))) ("Guatemala" (noun (singular . "Guatemalan") (plural . "Guatemalans")) (adjective (* . "Guatemalan"))) ("Guernsey" (noun (singular . "Channel Islander") (plural . "Channel Islanders")) (adjective (* . "Channel Islander"))) ("Guinea" (noun (singular . "Guinean") (plural . "Guineans")) (adjective (* . "Guinean"))) ("Guinea-Bissau" (noun (singular . "Guinean") (plural . "Guineans")) (adjective (* . "Guinean"))) ("Guyana" (noun (singular . "Guyanese") (plural . "Guyanese")) (adjective (* . "Guyanese"))) ("Haiti" (noun (singular . "Haitian") (plural . "Haitians")) (adjective (* . "Haitian"))) ("Heard Island and McDonald Islands" . #f) ("Herzegovina" (noun (singular . "Herzegovinian") (plural . "Herzegovinians")) (adjective (* . "Herzegovinian"))) ("Holy See (Vatican City)" . #f) ("Honduras" (noun (singular . "Honduran") (plural . "Hondurans")) (adjective (* . "Honduran"))) ("Hong Kong" (noun (* . "Hong Konger")) (adjective (* . "Hong Kong"))) ("Howland Island" . #f) ("Hungary" (noun (singular . "Hungarian") (plural . "Hungarians")) (adjective (* . "Hungarian"))) ("Iceland" (noun (singular . "Icelander") (plural . "Icelanders")) (adjective (* . "Icelandic"))) ("India" (noun (singular . "Indian") (plural . "Indians")) (adjective (* . "Indian"))) ("Indonesia" (noun (singular . "Indonesian") (plural . "Indonesians")) (adjective (* . "Indonesian"))) ("Iran" (noun (singular . "Iranian") (plural . "Iranians")) (adjective (* . "Iranian"))) ("Iraq" (noun (singular . "Iraqi") (plural . "Iraqis")) (adjective (* . "Iraqi"))) ("Ireland" (noun (masculine . "Irishman") (feminine . "Irishwoman") (plural . "Irish")) (adjective (* . "Irish"))) ("Israel" (noun (singular . "Israeli") (plural . "Israelis")) (adjective (* . "Israeli"))) ("Italy" (noun (singular . "Italian") (plural . "Italians")) (adjective (* . "Italian"))) ("Jamaica" (noun (singular . "Jamaican") (plural . "Jamaicans")) (adjective (* . "Jamaican"))) ("Jan Mayen" . #f) ("Japan" (noun (singular . "Japanese") (plural . "Japanese")) (adjective (* . "Japanese"))) ("Jarvis Island" . #f) ("Jersey" (noun (singular . "Channel Islander") (plural . "Channel Islanders")) (adjective (* . "Channel Islander"))) ("Johnston Atoll" . #f) ("Jordan" (noun (singular . "Jordanian") (plural . "Jordanians")) (adjective (* . "Jordanian"))) ("Juan de Nova Island" . #f) ("Kazakhstan" (noun (singular . "Kazakhstani") (plural . "Kazakhstanis")) (adjective (* . "Kazakhstani"))) ("Kenya" (noun (singular . "Kenyan") (plural . "Kenyans")) (adjective (* . "Kenyan"))) ("Kingman Reef" . #f) ("Kiribati" (noun (singular . "I-Kiribati") (plural . "I-Kiribati")) (adjective (* . "I-Kiribati"))) ("Korea, North" (noun (singular . "Korean") (plural . "Koreans")) (adjective (* . "Korean"))) ("Korea, South" (noun (singular . "Korean") (plural . "Koreans")) (adjective (* . "Korean"))) ("Kosovo" (noun (singular . "Kosovar") (plural . "Kosovars")) (adjective (* . "Kosovar"))) ("Kuwait" (noun (singular . "Kuwaiti") (plural . "Kuwaitis")) (adjective (* . "Kuwaiti"))) ("Kyrgyzstan" (noun (singular . "Kyrgyzstani") (plural . "Kyrgyzstanis")) (adjective (* . "Kyrgyzstani"))) ("Laos" (noun (singular . "Laotian") (plural . "Laotians")) (adjective (* . "Laotian"))) ("Latvia" (noun (singular . "Latvian") (plural . "Latvians")) (adjective (* . "Latvian"))) ("Lebanon" (noun (singular . "Lebanese") (plural . "Lebanese")) (adjective (* . "Lebanese"))) ("Lesotho" (noun (singular . "Mosotho") (plural . "Basotho")) (adjective (* . "Basotho"))) ("Liberia" (noun (singular . "Liberian") (plural . "Liberians")) (adjective (* . "Liberian"))) ("Libya" (noun (singular . "Libyan") (plural . "Libyans")) (adjective (* . "Libyan"))) ("Liechtenstein" (noun (singular . "Liechtensteiner") (plural . "Liechtensteiners")) (adjective (* . "Liechtenstein"))) ("Lithuania" (noun (singular . "Lithuanian") (plural . "Lithuanians")) (adjective (* . "Lithuanian"))) ("Luxembourg" (noun (singular . "Luxembourger") (plural . "Luxembourgers")) (adjective (* . "Luxembourg"))) ("Macau" (noun (* . "Chinese")) (adjective (* . "Chinese"))) ("Macedonia" (noun (singular . "Macedonian") (plural . "Macedonians")) (adjective (* . "Macedonian"))) ("Madagascar" (noun (singular . "Malagasy") (plural . "Malagasy")) (adjective (* . "Malagasy"))) ("Malawi" (noun (singular . "Malawian") (plural . "Malawians")) (adjective (* . "Malawian"))) ("Malaysia" (noun (singular . "Malaysian") (plural . "Malaysians")) (adjective (* . "Malaysian"))) ("Maldives, The" (noun (singular . "Maldivian") (plural . "Maldivians")) (adjective (* . "Maldivian"))) ("Mali" (noun (singular . "Malian") (plural . "Malians")) (adjective (* . "Malian"))) ("Malta" (noun (singular . "Maltese") (plural . "Maltese")) (adjective (* . "Maltese"))) ("Man, The Isle of" (noun (masculine . "Manxman") (feminine . "Manxwoman") (plural . "Manx")) (adjective (* . "Manx"))) ("Marshall Islands, The" (noun (singular . "Marshallese") (plural . "Marshallese")) (adjective (* . "Marshallese"))) ("Martinique" (noun (singular . "Martiniquais") (plural . "Martiniquais")) (adjective (* . "Martiniquais"))) ("Mauritania" (noun (singular . "Mauritanian") (plural . "Mauritanians")) (adjective (* . "Mauritanian"))) ("Mauritius" (noun (singular . "Mauritian") (plural . "Mauritians")) (adjective (* . "Mauritian"))) ("Mayotte" (noun (singular . "Mahorais") (plural . "Mahorais")) (adjective (* . "Mahoran"))) ("Mexico" (noun (singular . "Mexican") (plural . "Mexicans")) (adjective (* . "Mexican"))) ("Micronesia, The Federated States of" (noun (singular . "Micronesian") (plural . "Micronesians")) (adjective (* . "Micronesian"))) ("Midway Islands, The" . #f) ("Moldova" (noun (singular . "Moldovan") (plural . "Moldovans")) (adjective (* . "Moldovan"))) ("Monaco" (noun (singular . "Monacan") (plural . "Monacans")) (adjective (* . "Monacan"))) ("Mongolia" (noun (singular . "Mongolian") (plural . "Mongolians")) (adjective (* . "Mongolian"))) ("Montenegro" (noun (singular . "Montenegrin") (plural . "Montenegrins")) (adjective (* . "Montenegrin"))) ("Montserrat" (noun (singular . "Montserratian") (plural . "Montserratians")) (adjective (* . "Montserratian"))) ("Morocco" (noun (singular . "Moroccan") (plural . "Moroccans")) (adjective (* . "Moroccan"))) ("Mozambique" (noun (singular . "Mozambican") (plural . "Mozambicans")) (adjective (* . "Mozambican"))) ("Namibia" (noun (singular . "Namibian") (plural . "Namibians")) (adjective (* . "Namibian"))) ("Nauru" (noun (singular . "Nauruan") (plural . "Nauruans")) (adjective (* . "Nauruan"))) ("Navassa Island" . #f) ("Nepal" (noun (singular . "Nepalese") (plural . "Nepalese")) (adjective (* . "Nepalese"))) ("Netherlands, The" (noun (masculine . "Dutchman") (feminine . "Dutchwoman") (plural . "Dutch")) (adjective (* . "Dutch"))) ("Netherlands Antilles, The" (noun (singular . "Dutch Antillean") (plural . "Dutch Antilleans")) (adjective (* . "Dutch Antillean"))) ("Nevis" (noun (singular . "Nevisian") (plural . "Nevisians")) (adjective (* . "Nevisian"))) ("New Caledonia" (noun (singular . "New Caledonian") (plural . "New Caledonians")) (adjective (* . "New Caledonian"))) ("New Zealand" (noun (singular . "New Zealander") (plural . "New Zealanders")) (adjective (* . "New Zealand"))) ("Nicaragua" (noun (singular . "Nicaraguan") (plural . "Nicaraguans")) (adjective (* . "Nicaraguan"))) ("Niger" (noun (singular . "Nigerien") (plural . "Nigeriens")) (adjective (* . "Nigerien"))) ("Nigeria" (noun (singular . "Nigerian") (plural . "Nigerians")) (adjective (* . "Nigerian"))) ("Niue" (noun (singular . "Niuean") (plural . "Niueans")) (adjective (* . "Niuean"))) ("Norfolk Island" (noun (singular . "Norfolk Islander") (plural . "Norfolk Islanders")) (adjective (singular . "Norfolk Islander") (plural . "Norfolk Islanders"))) ("Northern Ireland" (noun (masculine . "Irishman") (feminine . "Irishwoman") (plural . "Irish")) (adjective (* . "Irish"))) ("Northern Mariana Islands, The" . #f) ("Norway" (noun (singular . "Norwegian") (plural . "Norwegians")) (adjective (* . "Norwegian"))) ("Oman" (noun (singular . "Omani") (plural . "Omanis")) (adjective (* . "Omani"))) ("Pakistan" (noun (singular . "Pakistani") (plural . "Pakistanis")) (adjective (* . "Pakistani"))) ("Palau" (noun (singular . "Palauan") (plural . "Palauans")) (adjective (* . "Palauan"))) ("Palestine" (noun (singular . "Palestinian") (plural . "Palestinians")) (adjective (* . "Palestinian"))) ("Palmyra Atoll" . #f) ("Panama" (noun (singular . "Panamanian") (plural . "Panamanians")) (adjective (* . "Panamanian"))) ("Papua New Guinea" (noun (singular . "Papua New Guinean") (plural . "Papua New Guineans")) (adjective (* . "Papua New Guinean"))) ("Paracel Islands, The" . #f) ("Paraguay" (noun (singular . "Paraguayan") (plural . "Paraguayans")) (adjective (* . "Paraguayan"))) ("Peru" (noun (singular . "Peruvian") (plural . "Peruvians")) (adjective (* . "Peruvian"))) ("Philippines, The" (noun (masculine . "Filipino") (feminine . "Filipina") (plural . "Filipinos")) (adjective (* . "Philippine"))) ("Pitcairn Islands, The" (noun (singular . "Pitcairn Islander") (plural . "Pitcairn Islanders")) (adjective (* . "Pitcairn Islander"))) ("Poland" (noun (singular . "Pole") (plural . "Poles")) (adjective (* . "Polish"))) ("Portugal" (noun (singular . "Portuguese") (plural . "Portuguese")) (adjective (* . "Portuguese"))) ("Puerto Rico" (noun (singular . "Puerto Rican") (plural . "Puerto Ricans")) (adjective (* . "Puerto Rican"))) ("Qatar" (noun (singular . "Qatari") (plural . "Qataris")) (adjective (* . "Qatari"))) ("Quebec" (noun (singular . "Quebecker") (plural . "Quebeckers")) (adjective (* . "Quebecker"))) ("Reunion" (noun (singular . "Reunionese") (plural . "Reunionese")) (adjective (* . "Reunionese"))) ("Romania" (noun (singular . "Romanian") (plural . "Romanians")) (adjective (* . "Romanian"))) ("Russia" (noun (singular . "Russian") (plural . "Russians")) (adjective (* . "Russian"))) ("Rwanda" (noun (singular . "Rwandan") (plural . "Rwandans")) (adjective (* . "Rwandan"))) ("Saint Helena" (noun (singular . "Saint Helenian") (plural . "Saint Helenians")) (adjective (* . "Saint Helenian"))) ("Saint Kitts" (noun (singular . "Kittitian") (plural . "Kittitians")) (adjective (* . "Kittitian"))) ("Saint Lucia" (noun (singular . "Saint Lucian") (plural . "Saint Lucians")) (adjective (* . "Saint Lucian"))) ("Saint Pierre and Miquelon" (noun (masculine . "Frenchman") (feminine . "Frenchwoman") (plural . "French")) (adjective (* . "French"))) ("Saint Vincent and the Grenadines" (noun (singular . "Saint Vincentian") (plural . "Saint Vincentians")) (adjective (* . "Saint Vincentian"))) ("Samoa" (noun (singular . "Samoan") (plural . "Samoans")) (adjective (* . "Samoan"))) ("San Marino" (noun (singular . "Sammarinese") (plural . "Sammarinese")) (adjective (* . "Sammarinese"))) ("Sao Tome and Principe" (noun (singular . "Sao Tomean") (plural . "Sao Tomeans")) (adjective (* . "Sao Tomean"))) ("Saudi Arabia" (noun (singular . "Saudi") (plural . "Saudis")) (adjective (* . "Saudi"))) ("Scotland" (noun (masculine . "Scotsman") (feminine . "Scotswoman") (plural . "Scots")) (adjective (* . "Scots"))) ("Senegal" (noun (singular . "Senegalese") (plural . "Senegalese")) (adjective (* . "Senegalese"))) ("Serbia" (noun (singular . "Serb") (plural . "Serbs")) (adjective (* . "Serbian"))) ("Seychelles, The" (noun (singular . "Seychellois") (plural . "Seychellois")) (adjective (* . "Seychellois"))) ("Sierra Leone" (noun (singular . "Sierra Leonean") (plural . "Sierra Leoneans")) (adjective (* . "Sierra Leonean"))) ("Singapore" (noun (singular . "Singaporean") (plural . "Singaporeans")) (adjective (* . "Singapore"))) ("Slovakia" (noun (singular . "Slovak") (plural . "Slovaks")) (adjective (* . "Slovak"))) ("Slovenia" (noun (singular . "Slovene") (plural . "Slovenes")) (adjective (* . "Slovenian"))) ("Solomon Islands, The" (noun (singular . "Solomon Islander") (plural . "Solomon Islanders")) (adjective (* . "Solomon Islander"))) ("Somalia" (noun (singular . "Somali") (plural . "Somalis")) (adjective (* . "Somali"))) ("South Africa" (noun (singular . "South African") (plural . "South Africans")) (adjective (* . "South African"))) ("South Georgia and the South Sandwich Islands" . #f) ("Spain" (noun (singular . "Spaniard") (plural . "Spaniards")) (adjective (* . "Spanish"))) ("Spratly Islands, The" . #f) ("Sri Lanka" (noun (singular . "Sri Lankan") (plural . "Sri Lankans")) (adjective (* . "Sri Lankan"))) ("Sudan" (noun (singular . "Sudanese") (plural . "Sudanese")) (adjective (* . "Sudanese"))) ("Suriname" (noun (singular . "Surinamer") (plural . "Surinamers")) (adjective (* . "Surinamese"))) ("Svalbard" . #f) ("Swaziland" (noun (singular . "Swazi") (plural . "Swazis")) (adjective (* . "Swazi"))) ("Sweden" (noun (singular . "Swede") (plural . "Swedes")) (adjective (* . "Swedish"))) ("Switzerland" (noun (singular . "Swiss") (plural . "Swiss")) (adjective (* . "Swiss"))) ("Syria" (noun (singular . "Syrian") (plural . "Syrians")) (adjective (* . "Syrian"))) ("Taiwan" (noun (* . "Taiwanese")) (adjective (* . "Taiwanese"))) ("Tajikistan" (noun (singular . "Tajikistani") (plural . "Tajikistanis")) (adjective (* . "Tajikistani"))) ("Tanzania" (noun (singular . "Tanzanian") (plural . "Tanzanians")) (adjective (* . "Tanzanian"))) ("Thailand" (noun (singular . "Thai") (plural . "Thai")) (adjective (* . "Thai"))) ("Tobago" (noun (singular . "Tobagonian") (plural . "Tobagonians")) (adjective (* . "Tobagonian"))) ("Togo" (noun (singular . "Togolese") (plural . "Togolese")) (adjective (* . "Togolese"))) ("Tokelau" (noun (singular . "Tokelauan") (plural . "Tokelauans")) (adjective (* . "Tokelauan"))) ("Tonga" (noun (singular . "Tongan") (plural . "Tongans")) (adjective (* . "Tongan"))) ("Trinidad" (noun (singular . "Trinidadian") (plural . "Trinidadians")) (adjective (* . "Trinidadian"))) ("Tromelin Island" . #f) ("Tunisia" (noun (singular . "Tunisian") (plural . "Tunisians")) (adjective (* . "Tunisian"))) ("Turkey" (noun (singular . "Turk") (plural . "Turks")) (adjective (* . "Turkish"))) ("Turkmenistan" (noun (singular . "Turkmen") (plural . "Turkmens")) (adjective (* . "Turkmen"))) ("Turks and Caicos Islands" . #f) ("Tuvalu" (noun (singular . "Tuvaluan") (plural . "Tuvaluans")) (adjective (* . "Tuvaluan"))) ("Uganda" (noun (singular . "Ugandan") (plural . "Ugandans")) (adjective (* . "Ugandan"))) ("Ukraine" (noun (singular . "Ukrainian") (plural . "Ukrainians")) (adjective (* . "Ukrainian"))) ("United Arab Emirates, The" (noun (singular . "Emirati") (plural . "Emiratis")) (adjective (* . "Emirati"))) ("United Kingdom, The" (noun (singular . "Briton") (plural . "Britons")) (adjective (* . "British"))) ("United States, The" (noun (singular . "American") (plural . "Americans")) (adjective (* . "American"))) ("Uruguay" (noun (singular . "Uruguayan") (plural . "Uruguayans")) (adjective (* . "Uruguayan"))) ("Uzbekistan" (noun (* . "Uzbekistani")) (adjective (* . "Uzbekistani"))) ("Vanuatu" (noun (singular . "Ni-Vanuatu") (plural . "Ni-Vanuatu")) (adjective (* . "Ni-Vanuatu"))) ("Venezuela" (noun (singular . "Venezuelan") (plural . "Venezuelans")) (adjective (* . "Venezuelan"))) ("Vietnam" (noun (singular . "Vietnamese") (plural . "Vietnamese")) (adjective (* . "Vietnamese"))) ("Virgin Islands, The" (noun (singular . "Virgin Islander") (plural . "Virgin Islanders")) (adjective (* . "Virgin Islander"))) ("Wake Island" . #f) ("Wales" (noun (masculine . "Welshman") (feminine . "Welshwoman") (plural "Welsh")) (adjective (* . "Welsh"))) ("Wallis and Futuna" (noun (* . "Wallis and Futuna Islanders")) (adjective (* . "Wallis and Futuna Islander"))) ("Western Sahara" (noun (singular . "Sahrawi") (plural . "Sahrawis")) (adjective (* . "Sahrawi"))) ("Yemen" (noun (singular . "Yemeni") (plural . "Yemenis")) (adjective (* . "Yemeni"))) ("Zambia" (noun (singular . "Zambian") (plural . "Zambians")) (adjective (* . "Zambian"))) ("Zimbabwe" (noun (singular . "Zimbabwean") (plural . "Zimbabweans")) (adjective (* . "Zimbabwean"))))
false
ac2e23f6933dec6c3a4458ae8d6e2e5b9f6ad881
0bd832b9b372ee7d4877e99b68536c15a7f7c9c9
/Chp3/3.26-multi-tree-local.rkt
4fef0b08223037066016847504ab64bc6c7d3da7
[]
no_license
jwilliamson1/schemer
eff9c10bcbcdea9110a44c80769a0334119b3da4
c2f9743392652664f1ff5687819f040e724c8436
refs/heads/master
2022-01-06T14:52:10.638822
2021-12-31T21:32:22
2021-12-31T21:32:22
75,143,723
0
0
null
2020-11-11T13:11:47
2016-11-30T02:37:55
Racket
UTF-8
Racket
false
false
3,755
rkt
3.26-multi-tree-local.rkt
#lang sicp (define (new-table) (define (make-entry key value) (cons key value)) (define (entry tree) (caar tree)) (define (left-branch tree) (cadr tree)) (define (right-branch tree) (caddr tree)) (define (make-tree entry left right) (list entry left right)) (define (make-tree-node x) (make-tree x '() '())) (define (set-left-branch! tree entry) (set-car! (cdr tree) entry)) (define (set-right-branch! tree entry) (set-car! (cddr tree) entry)) (let ((table (list '*table*))) (define (lookup keys) (let ((record (assoc keys (cdr table)))) (if record (cdr record) false))) (define (assoc keys records) (define (handle-matches keys record) (cond ((null? keys) record) ((pair? (cdr record)) (assoc keys (cdr record))) (else #f))) (display (list "assoc params" "KEYS:" keys "RECORDS:" records))(newline) (cond ((or (null? records) (null? (car records))) false) ((equal? (car keys) (caar records)) (handle-matches (cdr keys) (car records))) ((< (car keys) (caar records)) (assoc keys (left-branch records))) (else (assoc keys (right-branch records))))) (define (nest-trees-for-remaining-keys keys value) (display (list "null-set-handler params" "keys:" keys "value:" value)) (newline) (if (null? keys) value (make-tree-node (make-entry (car keys) (nest-trees-for-remaining-keys (cdr keys) value))))) ;(keys) -> atom b-> atom b|table a b-> atom b|table a b (define (match-handler keys value entry) (display (list "match-handler params" "keys:" keys "entry:" entry)) (newline) (cond ((null? keys) value) ((pair? entry) (adjoin-set! keys value entry)) (else (nest-trees-for-remaining-keys keys value)))) (define (adjoin-set! keys value set) (display (list "adjoin-set:" set)) (newline) (let ((new-key (car keys))) (cond ((null? set) (nest-trees-for-remaining-keys keys value)) ((eq? new-key (caar set)) (set-cdr! (car set) (match-handler (cdr keys) value (cdar set))) set) ((< new-key (entry set)) (set-left-branch! set (adjoin-set! keys value (left-branch set))) set) ((> new-key (entry set)) (set-right-branch! set (adjoin-set! keys value (right-branch set))) set)))) (define (insert-tree! keys value) (display (list "INSERT TREE PARAMS:" keys value table)) (set-cdr! table (adjoin-set! keys value (cdr table))) (display table) 'ok) (define (print) (display table)(newline)) (define (dispatch m) (cond ((eq? m 'lookup) (lambda (keys)(lookup keys))) ((eq? m 'print) print) ((eq? m 'insert) (lambda (keys value) (insert-tree! keys value))) (else "Invalid command"))) dispatch)) ;PROCEDURAL INTERFACES (define t4 (new-table)) (define (insert! table keys value) ((table 'insert) keys value)) (define (print table) ((table 'print))) (define (lookup table keys) ((table 'lookup) keys)) ;TESTS (insert! t4 '(76 -456) 'jesuit) (insert! t4 '(76 -834) 'chomsky) (insert! t4 '(76 -1000) 'regime) (insert! t4 '(50 1/2) 'francoi) (insert! t4 '(50 1/2 .333) 'twei) (insert! t4 '(50 1/2 .666) 'cambodia) (lookup t4 '(50 1/2 .333)) ;twei (lookup t4 '(76 -456)) ;false because it should have been overwritten (insert! t4 '(76 -456) 'carmelite) (print t4);(*table* (76 (-456 . carmelite) ((-834 . chomsky) ((-1000 . regime) () ()) ()) ()) ((50 (1/2 (0.333 . twei) () ((0.666 . cambodia) () ())) () ()) () ()) ())
false
04d5038a9798a91b984adb260796a01796f9f7dd
c01a4c8a6cee08088b26e2a2545cc0e32aba897b
/attic/medikanren/create-doid-cui-to-cid-hashtable.rkt
ad0408260399427a84549b59d0e93565ce3cce8a
[ "MIT" ]
permissive
webyrd/mediKanren
c8d25238db8afbaf8c3c06733dd29eb2d7dbf7e7
b3615c7ed09d176e31ee42595986cc49ab36e54f
refs/heads/master
2023-08-18T00:37:17.512011
2023-08-16T00:53:29
2023-08-16T00:53:29
111,135,120
311
48
MIT
2023-08-04T14:25:49
2017-11-17T18:03:59
Racket
UTF-8
Racket
false
false
775
rkt
create-doid-cui-to-cid-hashtable.rkt
#lang racket (require "create-hashtable-common.rkt") (provide (all-defined-out)) (define doid-ht (make-hash)) (define doid-ht-file-path (build-path HASHTABLE_SAVE_DIRECTORY "doid-hash.rkt")) (define (fill-doid-ht!) (set! doid-ht (make-hash)) (define add-to-ht! (add-concept-key/cid-associations-to-hashtable! doid-ht)) (add-to-ht! SEMMED #rx"DOID:([0-9]+)") (add-to-ht! RTX #rx"DOID:([0-9]+)") (add-to-ht! ROBOKOP #rx"DOID:([0-9]+)") (add-to-ht! ORANGE #rx"DOID:([0-9]+)") ) (define (save-doid-ht!) (save-hashtable! doid-ht doid-ht-file-path)) (define (load-doid-ht) (load-hashtable doid-ht-file-path)) (define (load-or-create/save-doid-ht!) (load-or-create/save-hashtable! 'doid load-doid-ht fill-doid-ht! save-doid-ht!))
false
350bc03582acecc5034a567b15b3a86181c91ab9
4919215f2fe595838a86d14926c10717f69784e4
/lessons/Making-Flags/lesson/lesson.scrbl
9be624afeda1ead2af96bbe3507704b2da54b863
[]
no_license
Emmay/curr
0bae4ab456a06a9d25fbca05a25aedfd5457819b
dce9cede1e471b0d12ae12d3121da900e43a3304
refs/heads/master
2021-01-18T08:47:20.267308
2013-07-15T12:23:41
2013-07-15T12:23:41
null
0
0
null
null
null
null
UTF-8
Racket
false
false
5,629
scrbl
lesson.scrbl
#lang curr/lib @declare-tags[pedagogy selftaught group] @lesson[#:title "Making Flags" #:duration "30 minutes" ]{ @itemlist/splicing[ @item{Here's some code to get you started: [@resource-link[#:path "source-files/Flags.rkt" #:label "DrRacket"] | @(hyperlink "http://www.wescheme.org/openEditor?publicId=LVUlaV7Z5J" "WeScheme")] @tag[selftaught]{@embedded-wescheme[#:id "Flags" #:definitions-text "(require bootstrap2012/bootstrap-teachpack) ; a blank flag is a 300x200 rectangle, which is outlined in black (define blank (rectangle 300 200 \"outline\" \"black\")) ; the Japanese flag is a red circle... (define japan (put-image (circle 50 \"solid\" \"red\") 150 100 ; put at (150, 100) blank)) ; on top of a blank flag"]}} @item{Let's look at the code that's in this file...} @item{First, you'll see that there's a definition called @code{red-dot}, which is a solid red circle of radius 50.} @item{There's also a definition for @code{blank}, which is a 300 x 200 rectangle that is outlined in black".} @pedagogy{@item{To make the flag of Japan, we want to place a red circle right in the middle of our @code{flag}. If our @code{flag} is 300 wide by 200 high, what coordinate will put us right at the center? 150, 100}} @tag[selftaught]{@item{@think-about[#:question (list "To make the flag of Japan, we want to place a red circle in the middle of our " @code{flag} ". If our " @code{flag} " is 300 wide by 200 high, what coordinate will put us right at the center?") #:answer "150, 100"]}} @pedagogy{@item{What should the radius of our circle be? What code will generate this circle? @code{(circle 50 "solid" "red")}}} @tag[selftaught]{@item{@think-about[#:question "What should the radius of our circle be? What code will generate this circle?" #:answer @code{(circle 50 "solid" "red")}]}} @pedagogy{@item{Let's go through the next exercise together.}} @item{@exercise{Place the red circle on top of the flag to make the Japanese flag.}} @item{@bitmap{images/japan.jpg} Okay, so I've got my background image, @code{flag}, and I've got the image I want to place on it. Scheme gives us a function called @code{put-image}, which lets us do exactly that! @code[#:multi-line #t]{; put-image: Image Number Number Image -> Image ; places an image, at position (x, y), on an Image}} @item{Let's set up some code, and then fill in the blanks: @code{(put-image ______ ___ ___ _______)}} @item{The first thing in @code{put-image}'s domain is the Image we want to place. What is our image? @pedagogy{A circle!} @code{(put-image (circle 50 "solid" "red") ___ ___ ________)}} @item{What are the next two things in the domain? @pedagogy{Numbers!} They represent the x and y coordinates for where we want to place the image of the circle. What did we determine were the coordinates for the center of the circle? Let's fill them in! @code{(put-image (circle 50 "solid" "red") 150 100 _______)}} @item{Finally, we need to give @code{put-image} another image. In our case, that's going to be our rectangle. @code[#:multi-line #t]{(put-image (circle 50 "solid" "red") 150 100 (rectangle 300 200 "outline" "black"))}} @item{Okay, so let's define this whole expression to be a variable, so we can use it later. What is a good name for this variable? @code[#:multi-line #t]{(define japan (put-image (circle 50 "solid" "red") 150 100 (rectangle 300 200 "outline" "black")))}} @item{Now let's click Run and evaluate @code{japan}. What do you think we will get back?} @item{We can actually make this a little more elegant, by using the power of @code{define}. Since we've already defined our circle as @code{red-dot} and our rectangle as @code{blank}, we can replace that code with the variable: @code[#:multi-line #t]{(put-image red-dot 150 100 blank)}} @item{Click "Run" and see if @code{japan} still does the right thing. How can we use @code{flag} to make the code even prettier?} @item{@exercise{@bitmap{images/somalia.jpg} Look at the picture of the Somalian flag. Think about what shapes will you need to make this flag. Which colors will you need? Try making the flag.}} @item{@exercise{@bitmap{images/poland.jpg} Look at the picture of the Polish flag. Think about what shapes will you need to make this flag. Which colors will you need? Try making the flag.}} @item{If you have time, try these other flags!} @item{@elem[#:style "NoFloat"]{@bitmap{images/indonesia.jpg}} @elem[#:style "NoFloat"]{@bitmap{images/peru.jpg}} @elem[#:style "NoFloat"]{@bitmap{images/switzerland.jpg}} @elem[#:style "NoFloat"]{@bitmap{images/france.jpg}} @elem[#:style "NoFloat"]{@bitmap{images/UAE.jpg}} @elem[#:style "NoFloat"]{@bitmap{images/chile.jpg}} @elem[#:style "NoFloat"]{@bitmap{images/panama.jpg}}} ]}
false
1eae77d9cec6668bf7d407da3546f03ec61c1c8b
7b04163039ff4cea3ac9b5b6416a134ee49ca1e4
/t/sql.t
31c75cd572e4572bf12a94de1408ce331ca1f7fb
[]
no_license
dstorrs/racket-dstorrs-libs
4c94219baf3c643a696aa17ed0e81d4a0ab18244
7e816d2b5f65a92ab01b29a320cc2c71d7870dbb
refs/heads/master
2022-08-27T22:31:38.985194
2022-08-05T21:35:35
2022-08-05T21:35:35
68,236,201
6
1
null
2018-10-19T15:37:12
2016-09-14T19:24:52
Racket
UTF-8
Racket
false
false
7,239
t
sql.t
#!/usr/bin/env racket #lang at-exp racket/base (require racket/format racket/function "../sql.rkt" "../test-more.rkt") (expect-n-tests 39) (void (ok #t "test harness is working")) (when #t (test-suite "join-related functions" (define c "collaborations") (define f "files") (is (join-table-name c f) "collaborations_to_files" "join-table-name works") (is (many-to-many-join c f) "collaborations c JOIN collaborations_to_files c2f ON c.id = c2f.collaboration_id JOIN files f ON c2f.file_id = f.id" "many-to-many-join works") (is (many-to-many-join c f #:skip-first? #t) "JOIN collaborations_to_files c2f ON c.id = c2f.collaboration_id JOIN files f ON c2f.file_id = f.id" "many-to-many-join with #:skip-first? works") (is (many-to-many-join c f #:skip-first? #t #:left? #t) "LEFT JOIN collaborations_to_files c2f ON c.id = c2f.collaboration_id LEFT JOIN files f ON c2f.file_id = f.id" "many-to-many-join with #:skip-first? and #:left? works") (is (many-to-many-join "collaborations" '("files" "endpoints")) "collaborations c JOIN collaborations_to_files c2f ON c.id = c2f.collaboration_id JOIN files f ON c2f.file_id = f.id JOIN collaborations_to_endpoints c2e ON c.id = c2e.collaboration_id JOIN endpoints e ON c2e.endpoint_id = e.id" "(many-to-many-join \"collaborations\" '(\"files\" \"endpoints\")) works") (is (many-to-many-join "collaborations" '("files" "endpoints") #:left? #t) "collaborations c LEFT JOIN collaborations_to_files c2f ON c.id = c2f.collaboration_id LEFT JOIN files f ON c2f.file_id = f.id LEFT JOIN collaborations_to_endpoints c2e ON c.id = c2e.collaboration_id LEFT JOIN endpoints e ON c2e.endpoint_id = e.id" @~a{(many-to-many-join "collaborations" '("files" "endpoints") #:left? #t) works}) (is (many-to-many-join "collaborations" '("files" "endpoints") #:skip-first? #t) "JOIN collaborations_to_files c2f ON c.id = c2f.collaboration_id JOIN files f ON c2f.file_id = f.id JOIN collaborations_to_endpoints c2e ON c.id = c2e.collaboration_id JOIN endpoints e ON c2e.endpoint_id = e.id" @~a{(many-to-many-join "collaborations" '("files" "endpoints") #:skip-first? #t) works}) (is (many-to-many-join "collaborations" '("files" "endpoints") #:skip-first? #t #:left? #t) "LEFT JOIN collaborations_to_files c2f ON c.id = c2f.collaboration_id LEFT JOIN files f ON c2f.file_id = f.id LEFT JOIN collaborations_to_endpoints c2e ON c.id = c2e.collaboration_id LEFT JOIN endpoints e ON c2e.endpoint_id = e.id" @~a{(many-to-many-join "collaborations" '("files" "endpoints") #:skip-first? #t) works}) (is (many-to-many-join "users" '("endpoints" "collaborations")) "users u JOIN endpoints_to_users e2u ON u.id = e2u.user_id JOIN endpoints e ON e2u.endpoint_id = e.id JOIN collaborations_to_users c2u ON u.id = c2u.user_id JOIN collaborations c ON c2u.collaboration_id = c.id" "(many-to-many-join \"users\" '(\"endpoints\" \"collaborations\")) works") (is (many-to-many-join "collaborations" '("files" "endpoints" "users")) "collaborations c JOIN collaborations_to_files c2f ON c.id = c2f.collaboration_id JOIN files f ON c2f.file_id = f.id JOIN collaborations_to_endpoints c2e ON c.id = c2e.collaboration_id JOIN endpoints e ON c2e.endpoint_id = e.id JOIN collaborations_to_users c2u ON c.id = c2u.collaboration_id JOIN users u ON c2u.user_id = u.id" "(many-to-many-join \"collaborations\" '(\"files\" \"endpoints\" \"users\")) works") (is (many-to-many-natural-join c f) "collaborations c NATURAL JOIN collaborations_to_files c2f NATURAL JOIN files f" "many-to-many-natural-join works") (is (many-to-many-natural-join "collaborations" '("files" "endpoints")) "collaborations c NATURAL JOIN collaborations_to_files c2f NATURAL JOIN files f NATURAL JOIN collaborations_to_endpoints c2e NATURAL JOIN endpoints e" "(many-to-many-natural-join \"collaborations\" '(\"files\" \"endpoints\")) works") (is (many-to-many-natural-join "users" '("endpoints" "collaborations")) "users u NATURAL JOIN endpoints_to_users e2u NATURAL JOIN endpoints e NATURAL JOIN collaborations_to_users c2u NATURAL JOIN collaborations c" "(many-to-many-natural-join \"users\" '(\"endpoints\" \"collaborations\")) works") (is (many-to-many-natural-join "collaborations" '("files" "endpoints" "users")) "collaborations c NATURAL JOIN collaborations_to_files c2f NATURAL JOIN files f NATURAL JOIN collaborations_to_endpoints c2e NATURAL JOIN endpoints e NATURAL JOIN collaborations_to_users c2u NATURAL JOIN users u" "(many-to-many-natural-join \"collaborations\" '(\"files\" \"endpoints\" \"users\")) works") ) ) (when #t (test-suite "sql-IN-clause" (is (sql-IN-clause '(foo bar)) "IN ($1,$2)" "correct: (sql-IN-clause '(foo bar))") (is (sql-IN-clause '(foo bar) 3) "IN ($3,$4)" "correct: (sql-IN-clause '(foo bar) 3)") (is (sql-IN-clause '((foo bar)(baz jaz))) "IN (($1,$2),($3,$4))" "correct: (sql-IN-clause '((foo bar)(baz jaz)))") (is (sql-IN-clause '((foo bar)(baz jaz)) 1) "IN (($1,$2),($3,$4))" "correct: (sql-IN-clause '((foo bar)(baz jaz)))") (is (sql-IN-clause '((foo bar)(baz jaz)) 3) "IN (($3,$4),($5,$6))" "correct: (sql-IN-clause '((foo bar)(baz jaz)) 3)") (throws (thunk (sql-IN-clause '((foo bar)(baz jaz)) 0)) exn:fail:contract? "start-from must be >= 1") (throws (thunk (sql-IN-clause '((foo bar)(baz)) 1)) #px"list of equal-length lists" "when setting up for multiple rows, all records must be the same length") (throws (thunk (sql-IN-clause '(()) 1)) exn:fail:contract? "can't have empty list in the data list") );test-suite );when (when #t (test-suite "placeholders-for" (for ((args (list '() '(foo) '(foo bar) '(foo bar 3) '(foo bar (1 2)))) (res (list "" "$1" "$1,$2" "$1,$2,$3" "$1,$2,$3" ))) (is (placeholders-for args) res @~a{(placeholders-for @args) is @res}) ) (is (placeholders-for '(foo bar 3) 3) "$3,$4,$5" @~a{(placeholders-for '(foo bar 3) 3) is "$3,$4,$5"}) (is (placeholders-for '(foo bar baz) 3 #:for-update? #t) "foo=$3,bar=$4,baz=$5" @~a{#:for-update? #t works}) ) ) (when #t (test-suite "placeholders-for-multiple-rows" (is (placeholders-for-multiple-rows '((a b c) (d e f))) "($1,$2,$3),($4,$5,$6)" "correctly built multiple-rows placeholders") (is (placeholders-for-multiple-rows '(a b c)) "($1,$2,$3)" "correctly built one-row placeholders from list") (is (placeholders-for-multiple-rows '((a b c) (d e f)) 3) "($3,$4,$5),($6,$7,$8)" "correctly built multiple-rows placeholders with start-from 3") (is (placeholders-for-multiple-rows '(a b c) 3) "($3,$4,$5)" "correctly built one-row placeholders from list with start-from 3") (is (placeholders-for-multiple-rows '((a b c)) 3) "($3,$4,$5)" "correctly built one-row placeholders from LoL with start-from 3") ) )
false
ace40a62b6df547382e8ffae9fcbf9379be672e0
310fec8271b09a726e9b4e5e3c0d7de0e63b620d
/badges/badge-colors.rkt
a12678ed906ed665f7655c07bf916e712349f93e
[ "Apache-2.0", "MIT" ]
permissive
thoughtstem/badge-bot
b649f845cdc4bf62ca6bd838f57353f8e508f1ae
e535eefac26f15061c412fd0eb5b7adee158a0bf
refs/heads/master
2022-12-14T21:55:00.173686
2020-09-21T19:54:15
2020-09-21T19:54:15
265,321,144
0
0
null
null
null
null
UTF-8
Racket
false
false
945
rkt
badge-colors.rkt
#lang racket (provide ca-color sr-color ws-color wser-color wsmg-color pyth-color wd-color baav-color basw-color bafn-color supo-color sumc-color adma-color adhp-color 3dex-color 3dor-color cpx-color derek-color ) (define ca-color 'gold) (define sr-color 'khaki) (define ws-color 'lightblue) (define wser-color 'steelblue) (define wsmg-color 'deepskyblue) (define pyth-color 'greenyellow) (define wd-color 'lightred) (define baav-color 'orange) (define basw-color 'gold) (define bafn-color 'orchid) (define supo-color 'royalblue) (define sumc-color 'saddlebrown) (define adma-color 'red) (define adhp-color 'cornflowerblue) (define 3dex-color 'forestgreen) (define 3dor-color 'slategray) (define cpx-color 'maroon) (define derek-color 'royalblue)
false
94139c99e015e86810f0a6f0f61ab62c45a269de
799b5de27cebaa6eaa49ff982110d59bbd6c6693
/soft-contract/test/programs/safe/termination/vazou/merge.rkt
ec7219139e36ee8f6ed0ac2a82f5bcf3bb7028e5
[ "MIT" ]
permissive
philnguyen/soft-contract
263efdbc9ca2f35234b03f0d99233a66accda78b
13e7d99e061509f0a45605508dd1a27a51f4648e
refs/heads/master
2021-07-11T03:45:31.435966
2021-04-07T06:06:25
2021-04-07T06:08:24
17,326,137
33
7
MIT
2021-02-19T08:15:35
2014-03-01T22:48:46
Racket
UTF-8
Racket
false
false
382
rkt
merge.rkt
#lang racket/base (require racket/match soft-contract/fake-contract) (define merge (match-lambda** [((cons x xs) (cons y ys)) (cond [(< x y) (cons x (merge xs (cons y ys)))] [else (cons y (merge (cons x xs) ys))])] [('() ys) ys] [(xs _) xs])) (provide (contract-out [merge ((listof real?) (listof real?) . -> . (listof real?) #:total? #t)]))
false
4e4a20c35796f1b84011fe0498161f7af259ccee
45d66c1749fe706a5ee2656722884b88fb3d63c7
/racketimpl/otherimpls/generatorflapjax.rkt
b9a9caa658701c72bad3d8f78f1286125313be26
[]
no_license
jn80842/frpsurvey
a7d5380f0c4fb7244bc659b7462ee4283f22c65d
2f3d61b1a8f7b164054690e680abe849fac5ce80
refs/heads/master
2021-01-11T19:47:20.039078
2019-01-25T07:18:11
2019-01-25T07:18:11
79,395,821
0
1
null
null
null
null
UTF-8
Racket
false
false
7,935
rkt
generatorflapjax.rkt
#lang racket (require racket/generator) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TODO ;; ;; rename to match flapjax ;; ;; distinguish evt & behavior ;; ;; merge produces tuples ;; ;; keep explicit track of time? ;; ;; symbolic execution ???? ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; simplifying assumption: inputs contain items for every tick of the clock ;; special symbol 'no-evt means no event occurred (define (no-evt? x) (equal? x 'no-evt)) (define (oneE) #t) (define (zeroE) (generator () (infinite-generator (yield 'no-evt)))) (define (mapE func evt-stream) (generator () (let loop ([evt (evt-stream)]) (begin (if (void? evt) (yield 'no-evt) (if (no-evt? evt) (yield evt) (yield (func evt)))) (loop (evt-stream)))))) (define (mergeE stream1 stream2) (generator () (let loop ([evt1 (stream1)] [evt2 (stream2)]) (begin (unless (no-evt? evt1) (yield evt1)) (unless (no-evt? evt2) (yield evt2)) (unless (not (and (no-evt? evt1) (no-evt? evt2))) (yield 'no-evt)) (loop (stream1) (stream2)))))) (define (switchE evt-stream) #t) (define (condE bool-evt-pair) #t) (define (filterE evt-stream pred) (generator () (let loop ([evt (evt-stream)]) (begin (if (pred evt) (yield evt) (yield 'no-evt)) (loop (evt-stream)))))) (define (ifE stream1 stream2 stream3) (generator () (let loop ([evt1 (stream1)] [evt2 (stream2)] [evt3 (stream3)]) (begin (if evt1 (yield evt2) (yield evt3)) (loop (stream1) (stream2) (stream3)))))) (define (constE const input-evt-stream) (generator () (let loop ([evt (input-evt-stream)]) (if (void? evt) 'no-evt (begin (yield (if (not (no-evt? evt)) const 'no-evt)) (loop (input-evt-stream))))))) (define (collectE evt-stream func init-val) (generator () (let loop ([prev-val init-val] [evt-val (evt-stream)]) (begin (let ([collected-val (func prev-val evt-val)]) (yield collected-val) (loop collected-val (evt-stream))))))) (define (andE stream1 stream2) #t) (define (orE stream1 stream2) #t) (define (notE stream) #t) (define (receiverE) #t) (define (sendEventE a evt-stream) #t) (define (filterRepeatE evt-stream) (generator () (let loop ([evt (evt-stream)] [prev-evt 'no-evt]) (begin (if (equal? evt prev-evt) (yield 'no-evt) (yield evt)) (loop (evt-stream) evt))))) (define (snapshotE evt-stream behavior) #t) (define (onceE evt-stream) #t) (define (skipFirstE evt-stream) #t) (define (delayE evt-stream delay-time) (generator () (let loop ([pending (list)] [evtVal (evt-stream)]) (begin (let ([ready (filter (λ (p) (equal? (first p) 0)) pending)] [still-pending (map (λ (p) (list (sub1 (first p)) (second p))) (filter (λ (p) (not (equal? (first p) 0))) pending))]) (if (equal? (length ready) 0) (yield 'no-evt) (for ([evt-pair ready]) (yield (second evt-pair)))) (loop (append still-pending (list (list delay-time evtVal))) (evt-stream))))))) (define (blindE evt-stream interval) (generator () (let loop ([evt (evt-stream)] [last-evt-time #f]) (if (and last-evt-time (> last-evt-time interval)) (begin (yield evt) (loop (evt-stream) 0)) (begin (yield 'no-evt) (loop (evt-stream) (add1 last-evt-time))))))) (define (calmE evt-stream interval-behavior) #t) (define (startsWith evt-stream init-val) (generator () (yield init-val) (let loop ([evt (evt-stream)] [val init-val]) (begin (if (or (no-evt? evt) (void? evt)) (begin (yield val) (loop (evt-stream) val)) (begin (yield evt) (loop (evt-stream) evt))))))) (define (changes behavior) #t) (define (constB const) (infinite-generator (yield const))) (define (delayB sourceB delay) #t) (define (switchB sourceBB) #t) (define (andB valueB1 valueB2) #t) (define (orB valueB1 valueB2) #t) (define (notB valueB) #t) (define (liftB func argB) #t) ;(define lift-behavior get-map-gen) ;; in this model they're the same thing (define (condB condResultB) #t) (define (ifB conditionB trueB falseB) #t) ;(define if-behavior get-if-gen) (define (timerB interval) #t) (define (blindB sourceB intervalB) #t) (define (calmB sourceB intervalB) #t) ;; so we can have infinite streams of events (define (get-event-stream gen) (generator () (let loop ([g (gen)]) (if (void? g) (yield 'no-evt) (yield g)) (loop (gen))))) ;;;;;; Web example ;;;;;;;;; (define inc-button (get-event-stream (sequence->generator (list 'click 'no-evt 'no-evt 'no-evt 'no-evt 'no-evt 'click)))) (define dec-button (get-event-stream (sequence->generator (list 'no-evt 'no-evt 'click 'click 'no-evt 'no-evt 'no-evt)))) (define inc-const-gen (constE 1 inc-button)) ;; 1 n n n n n 1 n n n ... (define dec-const-gen (constE -1 dec-button)) ;; n n -1 -1 n n n (define merged-buttons-gen (mergeE inc-const-gen dec-const-gen)) ;; 1 n n n -1 -1 n 1 n n n n (define collected-buttons-gen (collectE merged-buttons-gen (λ (l new) (if (not (no-evt? new)) (+ l new) l)) 0)) ;; 1 1 0 -1 -1 0 0 .... (define inc-dec-buttons-gen (startsWith collected-buttons-gen 0)) ;;;;;;; IoT example ;;;;;;; (define clock-times (get-event-stream (sequence->generator (list 2000 2030 2100 2101 2102 2103 2104 2105 2106 905 906 907 908 909 910 911 912)))) (define user-location (get-event-stream (sequence->generator (list "work" "car" "home" "home" "home" "home" "home" "home" "home" "home" "home" "home" "home")))) (define (motion-detector) (get-event-stream (sequence->generator (list 'no-evt 'no-evt #t 'no-evt 'no-evt 'no-evt 'no-evt 'no-evt 'no-evt #t)))) (define is-night-gen (get-map-gen (λ(v) (or (> v 2059) (< v 800))) clock-times)) (define home-or-away-gen (get-starts-with-gen (get-map-gen (λ(v) (if (equal? v "home") "home" "away")) user-location) "home")) (define mode-gen (get-if-gen is-night-gen (get-const-behavior "night") home-or-away-gen)) (define color-gen (get-if-gen is-night-gen (get-const-behavior 'orange) (get-const-behavior 'white))) (define light-on-gen (get-const-gen 'on (motion-detector))) (define light-off-gen (get-delay-gen (get-const-gen 'off (motion-detector)) 5)) (define merged-light-signals (get-merge-gen light-on-gen light-off-gen)) (define light-on-off-behavior (get-starts-with-gen merged-light-signals 'off)) (define is-light-on-behavior (lift-behavior (λ (v) (equal? v 'on)) light-on-off-behavior)) (define light-behavior (if-behavior is-light-on-behavior color-gen (get-const-behavior 'off)))
false
0beb15ced48f7cb00a736aab1c10cc99f7482f25
8c492ce2dfcb1e047c28de8753c173842fdaeb21
/tests/run.rkt
64ba6b035bd54ed1de7a0ab5d93b52a7eb9efecb
[]
no_license
carl-eastlund/refined-acl2
f8775e2f899e71778a1909d74066e6063b60d645
2e344ad7bcbc5b5a758296a8158dcf9a7f3880bd
refs/heads/master
2021-01-21T21:47:42.946847
2016-03-19T18:32:50
2016-03-19T18:32:50
12,603,459
2
1
null
2016-03-19T18:32:50
2013-09-04T22:22:07
Racket
UTF-8
Racket
false
false
913
rkt
run.rkt
#lang mischief (module+ main (require racket/cmdline) (define use-gui? #false) (command-line #:once-any ["--gui" "Use the RackUnit GUI." (set! use-gui? #true)] [{"--no-gui" "--text"} "Use the RackUnit textual interface (default)." (set! use-gui? #false)] #:args {} (if use-gui? ((dynamic-require 'rackunit/gui 'test/gui) #:wait? #true refined-acl2-tests) (exit ((dynamic-require 'rackunit/text-ui 'run-tests) refined-acl2-tests))))) (module+ test (require rackunit/text-ui) (run-tests refined-acl2-tests)) (require rackunit refined-acl2/tests/suite/atomic refined-acl2/tests/suite/modular refined-acl2/tests/suite/component refined-acl2/tests/suite/macro refined-acl2/tests/suite/surface) (define refined-acl2-tests (test-suite "Dracula" surface-tests #|macro-tests|# component-tests modular-tests atomic-tests))
false
29d097e31783dea73b415afd6d50fedd9106702f
76df16d6c3760cb415f1294caee997cc4736e09b
/rosette-benchmarks-3/bagpipe/src/bagpipe/racket/main/util/rosette.rkt
22980ae1147303aad0765b8527fe40e74130bb69
[ "MIT" ]
permissive
uw-unsat/leanette-popl22-artifact
70409d9cbd8921d794d27b7992bf1d9a4087e9fe
80fea2519e61b45a283fbf7903acdf6d5528dbe7
refs/heads/master
2023-04-15T21:00:49.670873
2021-11-16T04:37:11
2021-11-16T04:37:11
414,331,908
6
1
null
null
null
null
UTF-8
Racket
false
false
1,075
rkt
rosette.rkt
#lang s-exp rosette (require racket/hash (only-in rosette term-cache constant? model sat) (only-in rosette/base/core/type solvable-default get-type)) (provide solve/evaluate/concretize symbolic-void symbolic-boolean rosette-eq?) (define concretize (case-lambda [(sol) (concretize sol (filter constant? (hash-values (term-cache))))] [(sol consts) (match sol [(model bindings) (sat (hash-union bindings (for/hash ([c consts] #:unless (dict-has-key? bindings c)) (values c (solvable-default (get-type c))))))] [_ (error 'complete "expected a sat? solution, given ~a" sol)])])) (define-syntax-rule (solve/evaluate/concretize expr) (let* ([out (void)] [sol (solve (set! out (expr (void))))]) (if (unsat? sol) '(Uninhabited) (if (unknown? sol) '(Unknown) `(Solution ,(evaluate out (concretize sol))))))) (define (symbolic-void _) (assert false)) (define (((symbolic-boolean s) t) v) (define-symbolic* b boolean?) (if b (s v) (t v))) (define rosette-eq? eq?)
true
c5f4cbec89a217b58b0e5d9901349082285a2479
2bc995f30a2b738e593bd67df4ba719d8e584187
/private/sql-keywords.rkt
406d6afa8476434fb2ac420ca60c8a73cb90e813
[]
no_license
rmculpepper/sql
cea83029802e7391a28b59797c7d8c5056d79dac
f8722d186a5b2ebcbdd58b19a900ebb805bbf33e
refs/heads/master
2022-05-20T15:34:37.265926
2022-03-22T22:06:58
2022-03-24T14:35:43
32,065,057
31
5
null
2022-03-24T14:35:44
2015-03-12T08:13:32
Racket
UTF-8
Racket
false
false
58,912
rkt
sql-keywords.rkt
#lang racket/base (require racket/string racket/format racket/set) (provide (all-defined-out)) ;; This module contains the semi-processed tables used to generate keywords.rktd. ;; table : (Hash String => (Listof Symbol)) (define table (make-hash)) ;; table-add! : String (Listof Symbol) -> Void (define (table-add! word vals) (hash-set! table word (set-union (hash-ref table word null) vals))) ;; show-table : [(Listof Symbol)] -> Void (define (show-table [only-vals #f]) (define max-word-len (apply max (for/list ([w (hash-keys table)]) (string-length w)))) (define word-space (+ max-word-len 2)) (define all-vals (or only-vals (let ([vals-set (for/fold ([acc null]) ([(w vals) (in-hash table)]) (set-union acc vals))]) (sort vals-set symbol<?)))) (for ([word (sort (hash-keys table) string<?)]) (define vals (hash-ref table word)) (when (for/or ([val vals]) (memq val all-vals)) (printf "( ~a" (~a word #:width word-space)) (for ([val all-vals]) (cond [(memq val vals) (printf "~a " val)] [else (write-string (make-string (add1 (string-length (symbol->string val))) #\space))])) (printf " )\n")))) ;; ================================================================================ ;; Source: http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html ;; 0 1 2 3 4 5 6 ;; 0123456789012345678901234567890123456789012345678901234567890 ;; Key Word pg '11 '08 '92 ;; RS* = NOT RESERVED, but can't be function or type ;; no* = RESERVED, but can be function or type (define pg-table-src #<<end-of-table A n n ABORT n ABS RSV RSV ABSENT n n ABSOLUTE n n n RSV ACCESS n ACCORDING n n ACTION n n n RSV ADA n n n ADD n n n RSV ADMIN n n n AFTER n n n AGGREGATE n ALL RSV RSV RSV RSV ALLOCATE RSV RSV RSV ALSO n ALTER n RSV RSV RSV ALWAYS n n n ANALYSE RSV ANALYZE RSV AND RSV RSV RSV RSV ANY RSV RSV RSV RSV ARE RSV RSV RSV ARRAY RSV RSV RSV ARRAY_AGG RSV RSV ARRAY_MAX_CARDINALITY RSV AS RSV RSV RSV RSV ASC RSV n n RSV ASENSITIVE RSV RSV ASSERTION n n n RSV ASSIGNMENT n n n ASYMMETRIC RSV RSV RSV AT n RSV RSV RSV ATOMIC RSV RSV ATTRIBUTE n n n ATTRIBUTES n n AUTHORIZATION RSV RSV RSV RSV AVG RSV RSV RSV BACKWARD n BASE64 n n BEFORE n n n BEGIN n RSV RSV RSV BEGIN_FRAME RSV BEGIN_PARTITION RSV BERNOULLI n n BETWEEN RS* RSV RSV RSV BIGINT RS* RSV RSV BINARY no* RSV RSV BIT RS* RSV BIT_LENGTH RSV BLOB RSV RSV BLOCKED n n BOM n n BOOLEAN RS* RSV RSV BOTH RSV RSV RSV RSV BREADTH n n BY n RSV RSV RSV C n n n CACHE n CALL RSV RSV CALLED n RSV RSV CARDINALITY RSV RSV CASCADE n n n RSV CASCADED n RSV RSV RSV CASE RSV RSV RSV RSV CAST RSV RSV RSV RSV CATALOG n n n RSV CATALOG_NAME n n n CEIL RSV RSV CEILING RSV RSV CHAIN n n n CHAR RS* RSV RSV RSV CHARACTER RS* RSV RSV RSV CHARACTERISTICS n n n CHARACTERS n n CHARACTER_LENGTH RSV RSV RSV CHARACTER_SET_CATALOG n n n CHARACTER_SET_NAME n n n CHARACTER_SET_SCHEMA n n n CHAR_LENGTH RSV RSV RSV CHECK RSV RSV RSV RSV CHECKPOINT n CLASS n CLASS_ORIGIN n n n CLOB RSV RSV CLOSE n RSV RSV RSV CLUSTER n COALESCE RS* RSV RSV RSV COBOL n n n COLLATE RSV RSV RSV RSV COLLATION no* n n RSV COLLATION_CATALOG n n n COLLATION_NAME n n n COLLATION_SCHEMA n n n COLLECT RSV RSV COLUMN RSV RSV RSV RSV COLUMNS n n COLUMN_NAME n n n COMMAND_FUNCTION n n n COMMAND_FUNCTION_CODE n n COMMENT n COMMENTS n COMMIT n RSV RSV RSV COMMITTED n n n n CONCURRENTLY no* CONDITION RSV RSV CONDITION_NUMBER n n n CONFIGURATION n CONFLICT n CONNECT RSV RSV RSV CONNECTION n n n RSV CONNECTION_NAME n n n CONSTRAINT RSV RSV RSV RSV CONSTRAINTS n n n RSV CONSTRAINT_CATALOG n n n CONSTRAINT_NAME n n n CONSTRAINT_SCHEMA n n n CONSTRUCTOR n n CONTAINS RSV n CONTENT n n n CONTINUE n n n RSV CONTROL n n CONVERSION n CONVERT RSV RSV RSV COPY n CORR RSV RSV CORRESPONDING RSV RSV RSV COST n COUNT RSV RSV RSV COVAR_POP RSV RSV COVAR_SAMP RSV RSV CREATE RSV RSV RSV RSV CROSS no* RSV RSV RSV CSV n CUBE n RSV RSV CUME_DIST RSV RSV CURRENT n RSV RSV RSV CURRENT_CATALOG RSV RSV RSV CURRENT_DATE RSV RSV RSV RSV CURRENT_PATH RSV RSV CURRENT_ROLE RSV RSV RSV CURRENT_ROW RSV CURRENT_SCHEMA no* RSV RSV CURRENT_TIME RSV RSV RSV RSV CURRENT_TIMESTAMP RSV RSV RSV RSV CURRENT_USER RSV RSV RSV RSV CURSOR n RSV RSV RSV CURSOR_NAME n n n CYCLE n RSV RSV DATA n n n n DATABASE n DATALINK RSV RSV DATE RSV RSV RSV DATETIME_INTERVAL_CODE n n n DATETIME_INTERVAL_PRECISION n n n DAY n RSV RSV RSV DB n n DEALLOCATE n RSV RSV RSV DEC RS* RSV RSV RSV DECIMAL RS* RSV RSV RSV DECLARE n RSV RSV RSV DEFAULT RSV RSV RSV RSV DEFAULTS n n n DEFERRABLE RSV n n RSV DEFERRED n n n RSV DEFINED n n DEFINER n n n DEGREE n n DELETE n RSV RSV RSV DELIMITER n DELIMITERS n DENSE_RANK RSV RSV DEPTH n n DEREF RSV RSV DERIVED n n DESC RSV n n RSV DESCRIBE RSV RSV RSV DESCRIPTOR n n RSV DETERMINISTIC RSV RSV DIAGNOSTICS n n RSV DICTIONARY n DISABLE n DISCARD n DISCONNECT RSV RSV RSV DISPATCH n n DISTINCT RSV RSV RSV RSV DLNEWCOPY RSV RSV DLPREVIOUSCOPY RSV RSV DLURLCOMPLETE RSV RSV DLURLCOMPLETEONLY RSV RSV DLURLCOMPLETEWRITE RSV RSV DLURLPATH RSV RSV DLURLPATHONLY RSV RSV DLURLPATHWRITE RSV RSV DLURLSCHEME RSV RSV DLURLSERVER RSV RSV DLVALUE RSV RSV DO RSV DOCUMENT n n n DOMAIN n n n RSV DOUBLE n RSV RSV RSV DROP n RSV RSV RSV DYNAMIC RSV RSV DYNAMIC_FUNCTION n n n DYNAMIC_FUNCTION_CODE n n EACH n RSV RSV ELEMENT RSV RSV ELSE RSV RSV RSV RSV EMPTY n n ENABLE n ENCODING n n n ENCRYPTED n END RSV RSV RSV RSV END-EXEC RSV RSV RSV END_FRAME RSV END_PARTITION RSV ENFORCED n ENUM n EQUALS RSV n ESCAPE n RSV RSV RSV EVENT n EVERY RSV RSV EXCEPT RSV RSV RSV RSV EXCEPTION RSV EXCLUDE n n n EXCLUDING n n n EXCLUSIVE n EXEC RSV RSV RSV EXECUTE n RSV RSV RSV EXISTS RS* RSV RSV RSV EXP RSV RSV EXPLAIN n EXPRESSION n EXTENSION n EXTERNAL n RSV RSV RSV EXTRACT RS* RSV RSV RSV FALSE RSV RSV RSV RSV FAMILY n FETCH RSV RSV RSV RSV FILE n n FILTER n RSV RSV FINAL n n FIRST n n n RSV FIRST_VALUE RSV RSV FLAG n n FLOAT RS* RSV RSV RSV FLOOR RSV RSV FOLLOWING n n n FOR RSV RSV RSV RSV FORCE n FOREIGN RSV RSV RSV RSV FORTRAN n n n FORWARD n FOUND n n RSV FRAME_ROW RSV FREE RSV RSV FREEZE no* FROM RSV RSV RSV RSV FS n n FULL no* RSV RSV RSV FUNCTION n RSV RSV FUNCTIONS n FUSION RSV RSV G n n GENERAL n n GENERATED n n GET RSV RSV RSV GLOBAL n RSV RSV RSV GO n n RSV GOTO n n RSV GRANT RSV RSV RSV RSV GRANTED n n n GREATEST RS* GROUP RSV RSV RSV RSV GROUPING RS* RSV RSV GROUPS RSV HANDLER n HAVING RSV RSV RSV RSV HEADER n HEX n n HIERARCHY n n HOLD n RSV RSV HOUR n RSV RSV RSV ID n n IDENTITY n RSV RSV RSV IF n IGNORE n n ILIKE no* IMMEDIATE n n n RSV IMMEDIATELY n IMMUTABLE n IMPLEMENTATION n n IMPLICIT n IMPORT n RSV RSV IN RSV RSV RSV RSV INCLUDING n n n INCREMENT n n n INDENT n n INDEX n INDEXES n INDICATOR RSV RSV RSV INHERIT n INHERITS n INITIALLY RSV n n RSV INLINE n INNER no* RSV RSV RSV INOUT RS* RSV RSV INPUT n n n RSV INSENSITIVE n RSV RSV RSV INSERT n RSV RSV RSV INSTANCE n n INSTANTIABLE n n INSTEAD n n n INT RS* RSV RSV RSV INTEGER RS* RSV RSV RSV INTEGRITY n n INTERSECT RSV RSV RSV RSV INTERSECTION RSV RSV INTERVAL RS* RSV RSV RSV INTO RSV RSV RSV RSV INVOKER n n n IS no* RSV RSV RSV ISNULL no* ISOLATION n n n RSV JOIN no* RSV RSV RSV K n n KEY n n n RSV KEY_MEMBER n n KEY_TYPE n n LABEL n LAG RSV RSV LANGUAGE n RSV RSV RSV LARGE n RSV RSV LAST n n n RSV LAST_VALUE RSV RSV LATERAL RSV RSV RSV LEAD RSV RSV LEADING RSV RSV RSV RSV LEAKPROOF n LEAST RS* LEFT no* RSV RSV RSV LENGTH n n n LEVEL n n n RSV LIBRARY n n LIKE no* RSV RSV RSV LIKE_REGEX RSV RSV LIMIT RSV n n LINK n n LISTEN n LN RSV RSV LOAD n LOCAL n RSV RSV RSV LOCALTIME RSV RSV RSV LOCALTIMESTAMP RSV RSV RSV LOCATION n n n LOCATOR n n LOCK n LOCKED n LOGGED n LOWER RSV RSV RSV M n n MAP n n MAPPING n n n MATCH n RSV RSV RSV MATCHED n n MATERIALIZED n MAX RSV RSV RSV MAXVALUE n n n MAX_CARDINALITY RSV MEMBER RSV RSV MERGE RSV RSV MESSAGE_LENGTH n n n MESSAGE_OCTET_LENGTH n n n MESSAGE_TEXT n n n METHOD RSV RSV MIN RSV RSV RSV MINUTE n RSV RSV RSV MINVALUE n n n MOD RSV RSV MODE n MODIFIES RSV RSV MODULE RSV RSV RSV MONTH n RSV RSV RSV MORE n n n MOVE n MULTISET RSV RSV MUMPS n n n NAME n n n n NAMES n n n RSV NAMESPACE n n NATIONAL RS* RSV RSV RSV NATURAL no* RSV RSV RSV NCHAR RS* RSV RSV RSV NCLOB RSV RSV NESTING n n NEW RSV RSV NEXT n n n RSV NFC n n NFD n n NFKC n n NFKD n n NIL n n NO n RSV RSV RSV NONE RS* RSV RSV NORMALIZE RSV RSV NORMALIZED n n NOT RSV RSV RSV RSV NOTHING n NOTIFY n NOTNULL no* NOWAIT n NTH_VALUE RSV RSV NTILE RSV RSV NULL RSV RSV RSV RSV NULLABLE n n n NULLIF RS* RSV RSV RSV NULLS n n n NUMBER n n n NUMERIC RS* RSV RSV RSV OBJECT n n n OCCURRENCES_REGEX RSV RSV OCTETS n n OCTET_LENGTH RSV RSV RSV OF n RSV RSV RSV OFF n n n OFFSET RSV RSV RSV OIDS n OLD RSV RSV ON RSV RSV RSV RSV ONLY RSV RSV RSV RSV OPEN RSV RSV RSV OPERATOR n OPTION n n n RSV OPTIONS n n n OR RSV RSV RSV RSV ORDER RSV RSV RSV RSV ORDERING n n ORDINALITY n n n OTHERS n n OUT RS* RSV RSV OUTER no* RSV RSV RSV OUTPUT n n RSV OVER n RSV RSV OVERLAPS no* RSV RSV RSV OVERLAY RS* RSV RSV OVERRIDING n n OWNED n OWNER n P n n PAD n n RSV PARAMETER RSV RSV PARAMETER_MODE n n PARAMETER_NAME n n PARAMETER_ORDINAL_POSITION n n PARAMETER_SPECIFIC_CATALOG n n PARAMETER_SPECIFIC_NAME n n PARAMETER_SPECIFIC_SCHEMA n n PARSER n PARTIAL n n n RSV PARTITION n RSV RSV PASCAL n n n PASSING n n n PASSTHROUGH n n PASSWORD n PATH n n PERCENT RSV PERCENTILE_CONT RSV RSV PERCENTILE_DISC RSV RSV PERCENT_RANK RSV RSV PERIOD RSV PERMISSION n n PLACING RSV n n PLANS n PLI n n n POLICY n PORTION RSV POSITION RS* RSV RSV RSV POSITION_REGEX RSV RSV POWER RSV RSV PRECEDES RSV PRECEDING n n n PRECISION RS* RSV RSV RSV PREPARE n RSV RSV RSV PREPARED n PRESERVE n n n RSV PRIMARY RSV RSV RSV RSV PRIOR n n n RSV PRIVILEGES n n n RSV PROCEDURAL n PROCEDURE n RSV RSV RSV PROGRAM n PUBLIC n n RSV QUOTE n RANGE n RSV RSV RANK RSV RSV READ n n n RSV READS RSV RSV REAL RS* RSV RSV RSV REASSIGN n RECHECK n RECOVERY n n RECURSIVE n RSV RSV REF n RSV RSV REFERENCES RSV RSV RSV RSV REFERENCING RSV RSV REFRESH n REGR_AVGX RSV RSV REGR_AVGY RSV RSV REGR_COUNT RSV RSV REGR_INTERCEPT RSV RSV REGR_R2 RSV RSV REGR_SLOPE RSV RSV REGR_SXX RSV RSV REGR_SXY RSV RSV REGR_SYY RSV RSV REINDEX n RELATIVE n n n RSV RELEASE n RSV RSV RENAME n REPEATABLE n n n n REPLACE n REPLICA n REQUIRING n n RESET n RESPECT n n RESTART n n n RESTORE n n RESTRICT n n n RSV RESULT RSV RSV RETURN RSV RSV RETURNED_CARDINALITY n n RETURNED_LENGTH n n n RETURNED_OCTET_LENGTH n n n RETURNED_SQLSTATE n n n RETURNING RSV n n RETURNS n RSV RSV REVOKE n RSV RSV RSV RIGHT no* RSV RSV RSV ROLE n n n ROLLBACK n RSV RSV RSV ROLLUP n RSV RSV ROUTINE n n ROUTINE_CATALOG n n ROUTINE_NAME n n ROUTINE_SCHEMA n n ROW RS* RSV RSV ROWS n RSV RSV RSV ROW_COUNT n n n ROW_NUMBER RSV RSV RULE n SAVEPOINT n RSV RSV SCALE n n n SCHEMA n n n RSV SCHEMA_NAME n n n SCOPE RSV RSV SCOPE_CATALOG n n SCOPE_NAME n n SCOPE_SCHEMA n n SCROLL n RSV RSV RSV SEARCH n RSV RSV SECOND n RSV RSV RSV SECTION n n RSV SECURITY n n n SELECT RSV RSV RSV RSV SELECTIVE n n SELF n n SENSITIVE RSV RSV SEQUENCE n n n SEQUENCES n SERIALIZABLE n n n n SERVER n n n SERVER_NAME n n n SESSION n n n RSV SESSION_USER RSV RSV RSV RSV SET n RSV RSV RSV SETOF RS* SETS n n n SHARE n SHOW n SIMILAR no* RSV RSV SIMPLE n n n SIZE n n RSV SKIP n SMALLINT RS* RSV RSV RSV SNAPSHOT n SOME RSV RSV RSV RSV SOURCE n n SPACE n n RSV SPECIFIC RSV RSV SPECIFICTYPE RSV RSV SPECIFIC_NAME n n SQL n RSV RSV RSV SQLCODE RSV SQLERROR RSV SQLEXCEPTION RSV RSV SQLSTATE RSV RSV RSV SQLWARNING RSV RSV SQRT RSV RSV STABLE n STANDALONE n n n START n RSV RSV STATE n n STATEMENT n n n STATIC RSV RSV STATISTICS n STDDEV_POP RSV RSV STDDEV_SAMP RSV RSV STDIN n STDOUT n STORAGE n STRICT n STRIP n n n STRUCTURE n n STYLE n n SUBCLASS_ORIGIN n n n SUBMULTISET RSV RSV SUBSTRING RS* RSV RSV RSV SUBSTRING_REGEX RSV RSV SUCCEEDS RSV SUM RSV RSV RSV SYMMETRIC RSV RSV RSV SYSID n SYSTEM n RSV RSV SYSTEM_TIME RSV SYSTEM_USER RSV RSV RSV T n n TABLE RSV RSV RSV RSV TABLES n TABLESAMPLE no* RSV RSV TABLESPACE n TABLE_NAME n n n TEMP n TEMPLATE n TEMPORARY n n n RSV TEXT n THEN RSV RSV RSV RSV TIES n n TIME RS* RSV RSV RSV TIMESTAMP RS* RSV RSV RSV TIMEZONE_HOUR RSV RSV RSV TIMEZONE_MINUTE RSV RSV RSV TO RSV RSV RSV RSV TOKEN n n TOP_LEVEL_COUNT n n TRAILING RSV RSV RSV RSV TRANSACTION n n n RSV TRANSACTIONS_COMMITTED n n TRANSACTIONS_ROLLED_BACK n n TRANSACTION_ACTIVE n n TRANSFORM n n n TRANSFORMS n n TRANSLATE RSV RSV RSV TRANSLATE_REGEX RSV RSV TRANSLATION RSV RSV RSV TREAT RS* RSV RSV TRIGGER n RSV RSV TRIGGER_CATALOG n n TRIGGER_NAME n n TRIGGER_SCHEMA n n TRIM RS* RSV RSV RSV TRIM_ARRAY RSV RSV TRUE RSV RSV RSV RSV TRUNCATE n RSV RSV TRUSTED n TYPE n n n n TYPES n UESCAPE RSV RSV UNBOUNDED n n n UNCOMMITTED n n n n UNDER n n UNENCRYPTED n UNION RSV RSV RSV RSV UNIQUE RSV RSV RSV RSV UNKNOWN n RSV RSV RSV UNLINK n n UNLISTEN n UNLOGGED n UNNAMED n n n UNNEST RSV RSV UNTIL n UNTYPED n n UPDATE n RSV RSV RSV UPPER RSV RSV RSV URI n n USAGE n n RSV USER RSV RSV RSV RSV USER_DEFINED_TYPE_CATALOG n n USER_DEFINED_TYPE_CODE n n USER_DEFINED_TYPE_NAME n n USER_DEFINED_TYPE_SCHEMA n n USING RSV RSV RSV RSV VACUUM n VALID n n n VALIDATE n VALIDATOR n VALUE n RSV RSV RSV VALUES RS* RSV RSV RSV VALUE_OF RSV VARBINARY RSV RSV VARCHAR RS* RSV RSV RSV VARIADIC RSV VARYING n RSV RSV RSV VAR_POP RSV RSV VAR_SAMP RSV RSV VERBOSE no* VERSION n n n VERSIONING RSV VIEW n n n RSV VIEWS n VOLATILE n WHEN RSV RSV RSV RSV WHENEVER RSV RSV RSV WHERE RSV RSV RSV RSV WHITESPACE n n n WIDTH_BUCKET RSV RSV WINDOW RSV RSV RSV WITH RSV RSV RSV RSV WITHIN n RSV RSV WITHOUT n RSV RSV WORK n n n RSV WRAPPER n n n WRITE n n n RSV XML n RSV RSV XMLAGG RSV RSV XMLATTRIBUTES RS* RSV RSV XMLBINARY RSV RSV XMLCAST RSV RSV XMLCOMMENT RSV RSV XMLCONCAT RS* RSV RSV XMLDECLARATION n n XMLDOCUMENT RSV RSV XMLELEMENT RS* RSV RSV XMLEXISTS RS* RSV RSV XMLFOREST RS* RSV RSV XMLITERATE RSV RSV XMLNAMESPACES RSV RSV XMLPARSE RS* RSV RSV XMLPI RS* RSV RSV XMLQUERY RSV RSV XMLROOT RS* XMLSCHEMA n n XMLSERIALIZE RS* RSV RSV XMLTABLE RSV RSV XMLTEXT RSV RSV XMLVALIDATE RSV RSV YEAR n RSV RSV RSV YES n n n ZONE n n n RSV end-of-table ) (define (R s w) (and (member s '("RSV" "RS*" "no*")) w)) (for ([line (in-lines (open-input-string pg-table-src))]) (define word (string-downcase (string-trim (substring line 0 32)))) (define pgsql (R (string-trim (substring line 32 38)) 'pgsql)) (define sql11 (R (string-trim (substring line 38 44)) 'sql11)) (define sql08 (R (string-trim (substring line 44 50)) 'sql08)) (define sql92 (R (string-trim (substring line 50)) 'sql92)) (table-add! word (filter values (list sql92 pgsql sql11 sql08)))) ;; ================================================================================ ;; Source: https://dev.mysql.com/doc/refman/5.7/en/keywords.html (define mysql-table-src #<<end-of-table ACCESSIBLE **RESERVED** ACCOUNT ACTION ADD **RESERVED** AFTER AGAINST AGGREGATE ALGORITHM ALL **RESERVED** ALTER **RESERVED** ALWAYS ANALYSE ANALYZE **RESERVED** AND **RESERVED** ANY AS **RESERVED** ASC **RESERVED** ASCII ASENSITIVE **RESERVED** AT AUTOEXTEND_SIZE AUTO_INCREMENT AVG AVG_ROW_LENGTH BACKUP BEFORE **RESERVED** BEGIN BETWEEN **RESERVED** BIGINT **RESERVED** BINARY **RESERVED** BINLOG BIT BLOB **RESERVED** BLOCK BOOL BOOLEAN BOTH **RESERVED** BTREE BY **RESERVED** BYTE CACHE CALL **RESERVED** CASCADE **RESERVED** CASCADED CASE **RESERVED** CATALOG_NAME CHAIN CHANGE **RESERVED** CHANGED CHANNEL CHAR **RESERVED** CHARACTER **RESERVED** CHARSET CHECK **RESERVED** CHECKSUM CIPHER CLASS_ORIGIN CLIENT CLOSE COALESCE CODE COLLATE **RESERVED** COLLATION COLUMN **RESERVED** COLUMNS COLUMN_FORMAT COLUMN_NAME COMMENT COMMIT COMMITTED COMPACT COMPLETION COMPRESSED COMPRESSION CONCURRENT CONDITION **RESERVED** CONNECTION CONSISTENT CONSTRAINT **RESERVED** CONSTRAINT_CATALOG CONSTRAINT_NAME CONSTRAINT_SCHEMA CONTAINS CONTEXT CONTINUE **RESERVED** CONVERT **RESERVED** CPU CREATE **RESERVED** CROSS **RESERVED** CUBE CURRENT CURRENT_DATE **RESERVED** CURRENT_TIME **RESERVED** CURRENT_TIMESTAMP **RESERVED** CURRENT_USER **RESERVED** CURSOR **RESERVED** CURSOR_NAME DATA DATABASE **RESERVED** DATABASES **RESERVED** DATAFILE DATE DATETIME DAY DAY_HOUR **RESERVED** DAY_MICROSECOND **RESERVED** DAY_MINUTE **RESERVED** DAY_SECOND **RESERVED** DEALLOCATE DEC **RESERVED** DECIMAL **RESERVED** DECLARE **RESERVED** DEFAULT **RESERVED** DEFAULT_AUTH DEFINER DELAYED **RESERVED** DELAY_KEY_WRITE DELETE **RESERVED** DESC **RESERVED** DESCRIBE **RESERVED** DES_KEY_FILE DETERMINISTIC **RESERVED** DIAGNOSTICS DIRECTORY DISABLE DISCARD DISK DISTINCT **RESERVED** DISTINCTROW **RESERVED** DIV **RESERVED** DO DOUBLE **RESERVED** DROP **RESERVED** DUAL **RESERVED** DUMPFILE DUPLICATE DYNAMIC EACH **RESERVED** ELSE **RESERVED** ELSEIF **RESERVED** ENABLE ENCLOSED **RESERVED** ENCRYPTION END ENDS ENGINE ENGINES ENUM ERROR ERRORS ESCAPE ESCAPED **RESERVED** EVENT EVENTS EVERY EXCHANGE EXECUTE EXISTS **RESERVED** EXIT **RESERVED** EXPANSION EXPIRE EXPLAIN **RESERVED** EXPORT EXTENDED EXTENT_SIZE FALSE **RESERVED** FAST FAULTS FETCH **RESERVED** FIELDS FILE FILE_BLOCK_SIZE FILTER FIRST FIXED FLOAT **RESERVED** FLOAT4 **RESERVED** FLOAT8 **RESERVED** FLUSH FOLLOWS FOR **RESERVED** FORCE **RESERVED** FOREIGN **RESERVED** FORMAT FOUND FROM **RESERVED** FULL FULLTEXT **RESERVED** FUNCTION GENERAL GENERATED **RESERVED** GEOMETRY GEOMETRYCOLLECTION GET **RESERVED** GET_FORMAT GLOBAL GRANT **RESERVED** GRANTS GROUP **RESERVED** GROUP_REPLICATION HANDLER HASH HAVING **RESERVED** HELP HIGH_PRIORITY **RESERVED** HOST HOSTS HOUR HOUR_MICROSECOND **RESERVED** HOUR_MINUTE **RESERVED** HOUR_SECOND **RESERVED** IDENTIFIED IF **RESERVED** IGNORE **RESERVED** IGNORE_SERVER_IDS IMPORT IN **RESERVED** INDEX **RESERVED** INDEXES INFILE **RESERVED** INITIAL_SIZE INNER **RESERVED** INOUT **RESERVED** INSENSITIVE **RESERVED** INSERT **RESERVED** INSERT_METHOD INSTALL INSTANCE INT **RESERVED** INT1 **RESERVED** INT2 **RESERVED** INT3 **RESERVED** INT4 **RESERVED** INT8 **RESERVED** INTEGER **RESERVED** INTERVAL **RESERVED** INTO **RESERVED** INVOKER IO IO_AFTER_GTIDS **RESERVED** IO_BEFORE_GTIDS **RESERVED** IO_THREAD IPC IS **RESERVED** ISOLATION ISSUER ITERATE **RESERVED** JOIN **RESERVED** JSON KEY **RESERVED** KEYS **RESERVED** KEY_BLOCK_SIZE KILL **RESERVED** LANGUAGE LAST LEADING **RESERVED** LEAVE **RESERVED** LEAVES LEFT **RESERVED** LESS LEVEL LIKE **RESERVED** LIMIT **RESERVED** LINEAR **RESERVED** LINES **RESERVED** LINESTRING LIST LOAD **RESERVED** LOCAL LOCALTIME **RESERVED** LOCALTIMESTAMP **RESERVED** LOCK **RESERVED** LOCKS LOGFILE LOGS LONG **RESERVED** LONGBLOB **RESERVED** LONGTEXT **RESERVED** LOOP **RESERVED** LOW_PRIORITY **RESERVED** MASTER MASTER_AUTO_POSITION MASTER_BIND **RESERVED** MASTER_CONNECT_RETRY MASTER_DELAY MASTER_HEARTBEAT_PERIOD MASTER_HOST MASTER_LOG_FILE MASTER_LOG_POS MASTER_PASSWORD MASTER_PORT MASTER_RETRY_COUNT MASTER_SERVER_ID MASTER_SSL MASTER_SSL_CA MASTER_SSL_CAPATH MASTER_SSL_CERT MASTER_SSL_CIPHER MASTER_SSL_CRL MASTER_SSL_CRLPATH MASTER_SSL_KEY MASTER_SSL_VERIFY_SERVER_CERT **RESERVED** MASTER_TLS_VERSION MASTER_USER MATCH **RESERVED** MAXVALUE **RESERVED** MAX_CONNECTIONS_PER_HOUR MAX_QUERIES_PER_HOUR MAX_ROWS MAX_SIZE MAX_STATEMENT_TIME MAX_UPDATES_PER_HOUR MAX_USER_CONNECTIONS MEDIUM MEDIUMBLOB **RESERVED** MEDIUMINT **RESERVED** MEDIUMTEXT **RESERVED** MEMORY MERGE MESSAGE_TEXT MICROSECOND MIDDLEINT **RESERVED** MIGRATE MINUTE MINUTE_MICROSECOND **RESERVED** MINUTE_SECOND **RESERVED** MIN_ROWS MOD **RESERVED** MODE MODIFIES **RESERVED** MODIFY MONTH MULTILINESTRING MULTIPOINT MULTIPOLYGON MUTEX MYSQL_ERRNO NAME NAMES NATIONAL NATURAL **RESERVED** NCHAR NDB NDBCLUSTER NEVER NEW NEXT NO NODEGROUP NONBLOCKING NONE NOT **RESERVED** NO_WAIT NO_WRITE_TO_BINLOG **RESERVED** NULL **RESERVED** NUMBER NUMERIC **RESERVED** NVARCHAR OFFSET OLD_PASSWORD ON **RESERVED** ONE ONLY OPEN OPTIMIZE **RESERVED** OPTIMIZER_COSTS **RESERVED** OPTION **RESERVED** OPTIONALLY **RESERVED** OPTIONS OR **RESERVED** ORDER **RESERVED** OUT **RESERVED** OUTER **RESERVED** OUTFILE **RESERVED** OWNER PACK_KEYS PAGE PARSER PARSE_GCOL_EXPR PARTIAL PARTITION **RESERVED** PARTITIONING PARTITIONS PASSWORD PHASE PLUGIN PLUGINS PLUGIN_DIR POINT POLYGON PORT PRECEDES PRECISION **RESERVED** PREPARE PRESERVE PREV PRIMARY **RESERVED** PRIVILEGES PROCEDURE **RESERVED** PROCESSLIST PROFILE PROFILES PROXY PURGE **RESERVED** QUARTER QUERY QUICK RANGE **RESERVED** READ **RESERVED** READS **RESERVED** READ_ONLY READ_WRITE **RESERVED** REAL **RESERVED** REBUILD RECOVER REDOFILE REDO_BUFFER_SIZE REDUNDANT REFERENCES **RESERVED** REGEXP **RESERVED** RELAY RELAYLOG RELAY_LOG_FILE RELAY_LOG_POS RELAY_THREAD RELEASE **RESERVED** RELOAD REMOVE RENAME **RESERVED** REORGANIZE REPAIR REPEAT **RESERVED** REPEATABLE REPLACE **RESERVED** REPLICATE_DO_DB REPLICATE_DO_TABLE REPLICATE_IGNORE_DB REPLICATE_IGNORE_TABLE REPLICATE_REWRITE_DB REPLICATE_WILD_DO_TABLE REPLICATE_WILD_IGNORE_TABLE REPLICATION REQUIRE **RESERVED** RESET RESIGNAL **RESERVED** RESTORE RESTRICT **RESERVED** RESUME RETURN **RESERVED** RETURNED_SQLSTATE RETURNS REVERSE REVOKE **RESERVED** RIGHT **RESERVED** RLIKE **RESERVED** ROLLBACK ROLLUP ROTATE ROUTINE ROW ROWS ROW_COUNT ROW_FORMAT RTREE SAVEPOINT SCHEDULE SCHEMA **RESERVED** SCHEMAS **RESERVED** SCHEMA_NAME SECOND SECOND_MICROSECOND **RESERVED** SECURITY SELECT **RESERVED** SENSITIVE **RESERVED** SEPARATOR **RESERVED** SERIAL SERIALIZABLE SERVER SESSION SET **RESERVED** SHARE SHOW **RESERVED** SHUTDOWN SIGNAL **RESERVED** SIGNED SIMPLE SLAVE SLOW SMALLINT **RESERVED** SNAPSHOT SOCKET SOME SONAME SOUNDS SOURCE SPATIAL **RESERVED** SPECIFIC **RESERVED** SQL **RESERVED** SQLEXCEPTION **RESERVED** SQLSTATE **RESERVED** SQLWARNING **RESERVED** SQL_AFTER_GTIDS SQL_AFTER_MTS_GAPS SQL_BEFORE_GTIDS SQL_BIG_RESULT **RESERVED** SQL_BUFFER_RESULT SQL_CACHE SQL_CALC_FOUND_ROWS **RESERVED** SQL_NO_CACHE SQL_SMALL_RESULT **RESERVED** SQL_THREAD SQL_TSI_DAY SQL_TSI_HOUR SQL_TSI_MINUTE SQL_TSI_MONTH SQL_TSI_QUARTER SQL_TSI_SECOND SQL_TSI_WEEK SQL_TSI_YEAR SSL **RESERVED** STACKED START STARTING **RESERVED** STARTS STATS_AUTO_RECALC STATS_PERSISTENT STATS_SAMPLE_PAGES STATUS STOP STORAGE STORED **RESERVED** STRAIGHT_JOIN **RESERVED** STRING SUBCLASS_ORIGIN SUBJECT SUBPARTITION SUBPARTITIONS SUPER SUSPEND SWAPS SWITCHES TABLE **RESERVED** TABLES TABLESPACE TABLE_CHECKSUM TABLE_NAME TEMPORARY TEMPTABLE TERMINATED **RESERVED** TEXT THAN THEN **RESERVED** TIME TIMESTAMP TIMESTAMPADD TIMESTAMPDIFF TINYBLOB **RESERVED** TINYINT **RESERVED** TINYTEXT **RESERVED** TO **RESERVED** TRAILING **RESERVED** TRANSACTION TRIGGER **RESERVED** TRIGGERS TRUE **RESERVED** TRUNCATE TYPE TYPES UNCOMMITTED UNDEFINED UNDO **RESERVED** UNDOFILE UNDO_BUFFER_SIZE UNICODE UNINSTALL UNION **RESERVED** UNIQUE **RESERVED** UNKNOWN UNLOCK **RESERVED** UNSIGNED **RESERVED** UNTIL UPDATE **RESERVED** UPGRADE USAGE **RESERVED** USE **RESERVED** USER USER_RESOURCES USE_FRM USING **RESERVED** UTC_DATE **RESERVED** UTC_TIME **RESERVED** UTC_TIMESTAMP **RESERVED** VALIDATION VALUE VALUES **RESERVED** VARBINARY **RESERVED** VARCHAR **RESERVED** VARCHARACTER **RESERVED** VARIABLES VARYING **RESERVED** VIEW VIRTUAL **RESERVED** WAIT WARNINGS WEEK WEIGHT_STRING WHEN **RESERVED** WHERE **RESERVED** WHILE **RESERVED** WITH **RESERVED** WITHOUT WORK WRAPPER WRITE **RESERVED** X509 XA XID XML XOR **RESERVED** YEAR YEAR_MONTH **RESERVED** ZEROFILL **RESERVED** end-of-table ) (for ([line (in-lines (open-input-string mysql-table-src))]) (define linein (open-input-string line)) (define word (string-downcase (symbol->string (read linein)))) (define next (read linein)) (table-add! word (if (eq? next '**RESERVED**) '(mysql) '()))) ;; ================================================================================ ;; Source: https://sqlite.org/lang_keywords.html (define sqlite-table-src (map string-downcase (map symbol->string '(ABORT ACTION ADD AFTER ALL ALTER ANALYZE AND AS ASC ATTACH AUTOINCREMENT BEFORE BEGIN BETWEEN BY CASCADE CASE CAST CHECK COLLATE COLUMN COMMIT CONFLICT CONSTRAINT CREATE CROSS CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP DATABASE DEFAULT DEFERRABLE DEFERRED DELETE DESC DETACH DISTINCT DROP EACH ELSE END ESCAPE EXCEPT EXCLUSIVE EXISTS EXPLAIN FAIL FOR FOREIGN FROM FULL GLOB GROUP HAVING IF IGNORE IMMEDIATE IN INDEX INDEXED INITIALLY INNER INSERT INSTEAD INTERSECT INTO IS ISNULL JOIN KEY LEFT LIKE LIMIT MATCH NATURAL NO NOT NOTNULL NULL OF OFFSET ON OR ORDER OUTER PLAN PRAGMA PRIMARY QUERY RAISE RECURSIVE REFERENCES REGEXP REINDEX RELEASE RENAME REPLACE RESTRICT RIGHT ROLLBACK ROW SAVEPOINT SELECT SET TABLE TEMP TEMPORARY THEN TO TRANSACTION TRIGGER UNION UNIQUE UPDATE USING VACUUM VALUES VIEW VIRTUAL WHEN WHERE WITH WITHOUT)))) (for ([word (in-list sqlite-table-src)]) (table-add! word '(sqlite))) ;; ================================================================================ (define hand-annotations '[ ( avg sql92 -function) ( bigint pgsql mysql -type) ( bit sql92 pgsql -type) ( bit_length sql92 -function) ( blob mysql -type) ( boolean pgsql -type) ( char sql92 pgsql mysql -type) ( char_length sql92 -function) ( character sql92 pgsql mysql -type) ( character_length sql92 -function) ( coalesce sql92 pgsql -function) ( convert sql92 mysql -function) ( count sql92 -function) ( current_catalog pgsql -expr) ( current_date sql92 pgsql mysql sqlite -expr) ( current_role pgsql -expr) ( current_schema pgsql -expr) ( current_time sql92 pgsql mysql sqlite -expr) ( current_timestamp sql92 pgsql mysql sqlite -expr) ( current_user sql92 pgsql mysql -expr) ( date sql92 -type) ( decimal sql92 pgsql mysql -type) ( double sql92 mysql -type) ( false sql92 pgsql mysql -expr) ( float sql92 pgsql mysql -type) ( float4 mysql -type) ( float8 mysql -type) ( int sql92 pgsql mysql -type) ( int1 mysql -type) ( int2 mysql -type) ( int3 mysql -type) ( int4 mysql -type) ( int8 mysql -type) ( integer sql92 pgsql mysql -type) ( interval sql92 pgsql mysql -type) ( long mysql -type) ( longblob mysql -type) ( longtext mysql -type) ( lower sql92 -function) ( max sql92 -function) ( mediumblob mysql -type) ( mediumint mysql -type) ( mediumtext mysql -type) ( middleint mysql -type) ( min sql92 -function) ( null sql92 pgsql mysql sqlite -expr) ( nullif sql92 pgsql -function) ( numeric sql92 pgsql mysql -type) ( octet_length sql92 -function) ( position sql92 pgsql -function) ( smallint sql92 pgsql mysql -type) ( substring sql92 pgsql -function) ( sum sql92 -function) ( time sql92 pgsql -type) ( timestamp sql92 pgsql -type) ( tinyblob mysql -type) ( tinyint mysql -type) ( tinytext mysql -type) ( trim sql92 pgsql -function) ( true sql92 pgsql mysql -expr) ( upper sql92 -function) ( varbinary mysql -type) ( varchar sql92 pgsql mysql -type) ( varcharacter mysql -type) ( varying sql92 mysql -type) ]) (for ([entry hand-annotations]) (define word (symbol->string (car entry))) (define vals (set-intersect (cdr entry) '(-expr -function -type))) (table-add! word vals)) ;; ================================================================================ (module+ main (require racket/date) (define dialects '(sql92 pgsql mysql sqlite -expr -function -type)) (define h (make-hash)) (for ([(word vals) (in-hash table)]) (define vals* (set-intersect vals dialects)) (unless (null? vals*) (hash-set! h word vals*))) (printf ";; Generated by sql-keywords.rkt at ~a\n\n" (date->string (current-date) #t)) (write `(quote ,h)) (newline)) #| (define (write-definitions) (define dialects '(sql92 pgsql mysql sqlite)) (for ([dialect dialects]) (define reserved-words-var (string->symbol (format "~a-reserved-words" dialect))) (define reserved-words (sort (for/list ([(word ds) (in-hash table)] #:when (memq dialect ds)) word) string<?)) (write `(define ,reserved-words-var ',reserved-words)) (newline) (write `(provide ,reserved-words-var)) (newline))) |#
false
a6389d70bf9e84ab944e7615298f0d69bf917cd8
17126876cd4ff4847ff7c1fbe42471544323b16d
/beautiful-racket-demo/wires-demo/test-sources.rkt
81a8728d9d59f913675cd73ed372ae5667f7ef7e
[ "MIT" ]
permissive
zenspider/beautiful-racket
a9994ebbea0842bc09941dc6d161fd527a7f4923
1fe93f59a2466c8f4842f17d10c1841609cb0705
refs/heads/master
2020-06-18T11:47:08.444886
2019-07-04T23:21:02
2019-07-04T23:21:02
196,293,969
1
0
NOASSERTION
2019-07-11T00:47:46
2019-07-11T00:47:46
null
UTF-8
Racket
false
false
3,184
rkt
test-sources.rkt
#lang br (require br/test rackunit) (check-equal? (run-source "test.rkt") "d: 72 e: 507 f: 492 g: 114 h: 65412 i: 65079 x: 123 y: 456 ") (check-equal? (run-source "puzzle.rkt") "bo: 10292 ly: 4045 fq: 6560 cq: 15518 ga: 60815 u: 1 a: 46065 ay: 65531 hf: 15568 lr: 8187 lu: 7027 ek: 15935 cy: 0 hv: 1438 bi: 1 ik: 9873 t: 0 ed: 128 ko: 2047 bx: 65515 cu: 63740 q: 65533 lx: 46065 lp: 64761 fw: 16329 r: 1997 dk: 3655 bj: 4 ce: 10 ij: 59287 gj: 59011 ld: 8090 lw: 46064 lc: 23032 an: 0 gq: 7140 lh: 1011 g: 245 lo: 774 db: 26676 cz: 22 cg: 20584 fg: 4096 iu: 64720 kz: 14054 cn: 513 bk: 5 hc: 29505 jh: 9280 bt: 64509 kw: 16374 kv: 2514 il: 65457 v: 837 jn: 32360 fr: 1640 bh: 23539 gd: 57743 hm: 15858 lf: 8090 av: 525 fo: 52486 hp: 9506 ln: 2031 ky: 63215 km: 2022 en: 15935 fu: 65503 ji: 56255 jp: 32360 gw: 8704 l: 160 fm: 19718 jx: 8126 eq: 89 lz: 32768 ez: 65471 jq: 8090 ej: 2597 dn: 62970 kc: 4640 bf: 0 fl: 179 dy: 13338 lm: 783 ef: 1827 ft: 32 kq: 65055 kk: 16180 da: 22 au: 2100 ar: 0 fn: 32768 fj: 1 hx: 31136 lg: 2022 kj: 0 eh: 1282 id: 8189 li: 252 br: 5406 gt: 58975 gh: 26243 cc: 39417 ec: 1955 ls: 1160 m: 65375 ib: 7988 dj: 65279 ll: 65295 jr: 4045 js: 1011 bg: 65535 w: 32768 fk: 178 jm: 5758 im: 8320 eg: 3879 gz: 1 le: 0 bu: 4380 co: 65022 x: 33605 k: 487 ge: 1 ih: 16121 gp: 64495 ee: 65407 jy: 3098 ff: 47903 az: 2617 fi: 43807 jl: 5758 ha: 718 y: 8401 dd: 26676 bn: 41169 ie: 1796 z: 4200 lk: 240 cf: 11 bc: 65495 hl: 6642 gc: 62463 s: 1 fz: 11401 fe: 12562 eo: 1 ab: 5242 bm: 32768 hi: 8186 lb: 23032 ci: 53352 la: 0 gg: 359 gk: 14752 de: 6669 lt: 64375 lj: 1023 jt: 4095 ax: 4 c: 0 hr: 8448 ig: 6393 ew: 1232 bs: 1026 h: 16 ma: 36813 lv: 1 je: 59339 hb: 719 er: 6669 iv: 16180 hs: 57087 bl: 8401 kl: 4045 p: 2 lq: 1257 cr: 5130 do: 5194 cj: 13338 be: 23539 gi: 32768 ic: 1997 ep: 88 ks: 4063 gv: 59079 hh: 1946 fh: 61439 hj: 1544 o: 1999 jo: 0 hd: 32768 dc: 0 kn: 505 ck: 6669 ba: 6777 iw: 8090 kr: 1567 ei: 64253 as: 16802 jb: 6268 df: 3334 bp: 5146 cd: 1 bb: 40 aj: 47079 kx: 2320 ap: 2 ea: 1667 aq: 16802 fc: 1665 kt: 1549 ii: 6248 di: 256 fy: 60607 n: 327 bq: 1286 kp: 480 dx: 0 ia: 15976 am: 47078 ch: 32768 he: 62273 hg: 7784 bz: 47609 ku: 63986 ac: 8 al: 65534 cx: 63740 if: 63739 dz: 3334 it: 32768 dl: 7759 aw: 2621 jj: 56216 cv: 0 eb: 416 hz: 63904 fb: 14227 gl: 7376 gb: 3072 jk: 0 kb: 32748 dm: 2565 fa: 6033 dh: 3911 jc: 16252 aa: 1050 hk: 63991 in: 57215 gf: 358 hy: 32768 ir: 2879 ix: 2022 fd: 63870 em: 65535 cm: 7823 ev: 4929 iq: 2878 cl: 1667 jd: 6196 dg: 833 at: 4200 jz: 62437 ai: 13475 dt: 0 ka: 5028 du: 44 fv: 8136 ki: 16180 iz: 1922 iy: 8190 es: 32768 ey: 64 bd: 6737 fx: 4928 jf: 10056 eu: 9859 kh: 11516 jg: 65496 et: 39437 fp: 13121 cb: 57343 by: 14632 ao: 2 cp: 7310 af: 13555 ca: 8192 kf: 0 jw: 3134 fs: 8168 el: 0 kd: 60895 ex: 6097 dp: 31870 cw: 65535 gu: 8772 dw: 13338 gx: 56831 ja: 63613 ip: 1 ah: 65455 f: 52 cs: 60405 ke: 28108 ju: 961 ct: 10388 io: 57137 jv: 64574 dv: 44 dq: 0 d: 418 kg: 11516 dr: 65535 bv: 14652 gr: 15332 hq: 63331 i: 65519 hn: 6352 gy: 50375 ak: 1 bw: 20 ht: 54883 is: 31952 gm: 1844 j: 229 gs: 6560 ds: 31870 e: 209 go: 1040 gn: 8180 ag: 80 hw: 1439 b: 1674 ae: 5234 ad: 65527 hu: 1 ho: 59183 ")
false
e543bfc09e2ea171b3c1e19abb089296d6422f8c
a70301d352dcc9987daf2bf12919aecd66defbd8
/tower/small-ex/sobj/lang/reader.rkt
532c3ae5949c0511ea9074a3f1db8bba1289fa40
[]
no_license
mflatt/talks
45fbd97b1ca72addecf8f4b92053b85001ed540b
7abfdf9a9397d3d3d5d1b4c107ab6a62d0ac1265
refs/heads/master
2021-01-19T05:18:38.094408
2020-06-04T16:29:25
2020-06-04T16:29:25
87,425,078
2
2
null
null
null
null
UTF-8
Racket
false
false
1,432
rkt
reader.rkt
#lang racket (require "parser.rkt" parser-tools/lex) (provide read-syntax get-info color-lexer) ;; To read a module: (define (read-syntax src-name in) (port-count-lines! in) (define stx (parse src-name in)) (datum->syntax #f `(module prog sobj ,stx))) ;; To get info about the language's environment support: (define (get-info in mod line col pos) (lambda (key default) (case key [(color-lexer) color-lexer] [else default]))) ;; Environment support for token coloring: (define (color-lexer in offset mode) ;; Get next token: (define tok (lex in)) ;; Package classification with srcloc: (define (ret mode paren) (values (token->string (position-token-token tok) (token-value (position-token-token tok))) mode paren (position-offset (position-token-start-pos tok)) (position-offset (position-token-end-pos tok)) 0 #f)) ;; Convert token to classification: (case (token-name (position-token-token tok)) [(EOF) (ret 'eof #f)] [(COPEN) (ret 'parenthesis '|{|)] [(CCLOSE) (ret 'parenthesis '|}|)] [(SOPEN) (ret 'parenthesis '|[|)] [(SCLOSE) (ret 'parenthesis '|]|)] [(NUM) (ret 'literal #f)] [(WHITESPACE) (ret 'white-space #f)] [(DOT ASSIGN PLUS SEMICOLON) (ret 'other #f)] [(ERROR) (ret 'error #f)] [else (ret 'symbol #f)]))
false
225941ddc203e3e10a2a82cd02d41aa4525d7334
80573ab25f4d751043daab38fb95038341dac5d9
/racket/docs/repl-grafico.rkt
eef8a12b098d3612221c817e66d27a5c0727f89c
[]
no_license
juliowaissman/tesis
cdd602e957623030402d98718b3992c81e8b4d9c
f94a140c64df49ddc27c4c3a731ba3ba9e5971ce
refs/heads/master
2021-01-15T13:06:38.684844
2016-08-16T23:12:40
2016-08-16T23:12:40
null
0
0
null
null
null
null
UTF-8
Racket
false
false
7,494
rkt
repl-grafico.rkt
#lang racket/gui (require "estructuras.rkt" "lector.rkt" "escritor.rkt" "evaluador.rkt" framework pict pict/snip) (define ventana (new frame% [label "REPL"] [width 800] [min-width 200] [height 600] [min-height 200])) (define panel-principal (new panel:vertical-dragable% [parent ventana])) (define lienzo-historial (new editor-canvas% [parent panel-principal])) (define editor-historial% (class text% (define bloqueado? #t) (define/augment (can-insert? s l) (not bloqueado?)) (define/augment (can-delete? s l) #f) (define/public (insertar snip-entrada snip-salida) (set! bloqueado? #f) (send this insert #\newline (send this last-position)) (send this insert snip-entrada (send this last-position)) (send this insert (new pict-snip% [pict (arrow 10 0)]) (send this last-position)) (send this insert snip-salida (send this last-position)) (send this insert #\newline (send this last-position)) (set! bloqueado? #t)) (define/public (mostrar-ayuda) (set! bloqueado? #f) (send this insert "\nINFORMACIÓN DE AYUDA\n\nLa siguiente tabla contiene los atajos del teclado para el cuadro de texto de abajo\n`c:' es la tecla Ctrl y `m:' es la tecla Alt\n\n" (send this last-position)) (send this insert (new pict-snip% [pict (table 2 (map (lambda (x) (text (format "~a" x))) lista-de-atajos) cc-superimpose cc-superimpose 10 10)]) (send this last-position)) (send this insert "\nEl contenido de los cuadros que aparecen después de una evaluación puede ser\ncopiado al cuadro de texto de abajo haciéndole clic\n\nPara cambiar el modo de escritura entre `formal' (F) y `breve' (B) presiona el botón\ncon la letra correspondiente.\n\n" (send this last-position)) (set! bloqueado? #t)) (super-new) (send this hide-caret #t) (set! bloqueado? #f) (send this insert "Bienvenido al mundo del cálculo λ.\n\nEn el cuadro de texto de abajo puedes escribir expresiones, para\nevaluarlas solo tienes que presionar el botón etiquetado con la λ!!!\n\nPara un mensaje de ayuda presiona el botón con el signo de interrogación.\n\n") (set! bloqueado? #t))) (define editor-historial (new editor-historial%)) (send lienzo-historial set-editor editor-historial) (define expresion-snip% (class editor-snip% (init-field [cadena ""]) (define/override (on-event dc x y editorx editory event) (if (eq? 'left-down (send event get-event-type)) (send campo-entrada set-value cadena) (send campo-entrada focus))) (super-new) (define txt (new text%)) (send txt change-style (make-object style-delta% 'change-size 10)) (send txt change-style (make-object style-delta% 'change-family 'modern)) (send txt insert cadena) (send this set-editor txt))) (define panel-entrada (new horizontal-panel% [parent panel-principal] [alignment '(left top)])) (define campo-entrada (new text-field% [label " > "] [parent panel-entrada] [style '(multiple)] [font (make-object font% 10 'modern)])) (define atajos-teclado (new keymap%)) (define lista-de-atajos null) (define-syntax define-atajo (syntax-rules () [(_ (nombre . argumentos) teclas cuerpo ...) (let ([nombre* (symbol->string 'nombre)]) (send atajos-teclado add-function nombre* (lambda argumentos cuerpo ...)) (send atajos-teclado map-function teclas nombre*) (set! lista-de-atajos (append (list teclas nombre*) lista-de-atajos)))])) (define-atajo (inserta-lambda x e) "m:l" (send x insert "λ")) (define-atajo (inserta-alpha x e) "m:a" (send x insert "α")) (define-atajo (inserta-beta x e) "m:b" (send x insert "β")) (define-atajo (selecciona-todo x e) "c:a" (send x do-edit-operation 'select-all)) (define-atajo (deshacer x e) "c:z" (send x do-edit-operation 'undo)) (define-atajo (rehacer x e) "c:y" (send x do-edit-operation 'redo)) (define-atajo (copiar x e) "c:c" (send x do-edit-operation 'copy)) (define-atajo (pegar x e) "c:v" (send x do-edit-operation 'paste)) (define-atajo (cortar x e) "c:x" (send x do-edit-operation 'cut)) (define-atajo (enviar-entrada x e) "c:enter" (enviar-texto)) (define-atajo (inserta-tab x e) "tab" (send x insert " ")) (send (send campo-entrada get-editor) set-keymap atajos-teclado) (define panel-botones (new vertical-panel% [parent panel-entrada] [stretchable-width #f])) (define boton-entrada (new button% [label "λ"] [parent panel-botones] [callback (lambda (b e) (when (eq? 'button (send e get-event-type)) (enviar-texto)))])) (define boton-ayuda (new button% [label "?"] [parent panel-botones] [callback (lambda (b e) (when (eq? 'button (send e get-event-type)) (send editor-historial mostrar-ayuda)))])) (define modo-escritura 'formal) (define boton-escritura (new button% [label "B"] [parent panel-botones] [callback (lambda (b e) (when (eq? 'button (send e get-event-type)) (if (eq? modo-escritura 'formal) (begin (send boton-escritura set-label "F") (set! modo-escritura 'breve)) (begin (send boton-escritura set-label "B") (set! modo-escritura 'formal)))))])) (define (enviar-texto) (define entrada (send campo-entrada get-value)) (define parseado (with-handlers ([exn:fail? (lambda (exn) (list 'error (exn-message exn)))]) (leer (open-input-string entrada)))) (define evaluado (if (and (list? parseado) (eq? 'error (car parseado))) parseado (with-handlers ([exn:fail? (lambda (exn) (list 'error (exn-message exn)))]) (evaluar-expresión parseado)))) (define salida (cond [(expresión? evaluado) ((if (eq? modo-escritura 'formal) expresión->texto-plano expresión->abuso-texto-plano) evaluado)] [(and (list? evaluado) (eq? 'error (car evaluado))) (cadr evaluado)] [else (format "~v" evaluado)])) (send editor-historial insertar (new expresion-snip% [cadena entrada]) (new expresion-snip% [cadena salida])) (send campo-entrada set-value "") (send campo-entrada focus)) (send ventana show #t)
true
c001d017b8869d1317fc14ad920b5012a4590128
9631ee1be66876f7152a88caf09a60e568c78082
/day7.rkt
1feeda446da9ab8dce5a327b4a9157a5b916eb9b
[]
no_license
ebresafegaga/aoc2020
43035c673d9ad5193db8b42e858275066b2043d0
766dddbe7a66a1fe35e7343810d1f8a5757e61c8
refs/heads/main
2023-03-17T21:02:43.682781
2021-03-01T18:40:40
2021-03-01T18:40:40
343,519,585
0
0
null
null
null
null
UTF-8
Racket
false
false
2,151
rkt
day7.rkt
#lang racket/base (require racket/require (multi-in racket (match file runtime-path list)) megaparsack megaparsack/text data/applicative data/monad) (struct bag (name) #:transparent) (struct rule (bag items) #:transparent) (define (can-hold-bag b rules r) (match r [(rule bag bags) (let ([bags* (map cdr bags)]) (or (member b bags*) (ormap (λ (b*) (let ([rule (hash-ref rules b* (λ () (rule b* (list))))]) (can-hold-bag b rules rule))) bags*)))])) (define (count-bags b rules) (let ([b-rule (hash-ref rules b)]) (match b-rule [(rule _ bags) (apply + (map (λ (b) (let ([count (car b)] [inner-bag (cdr b)]) (+ count (* count (count-bags inner-bag rules))))) bags))]))) (define space*/p (many/p space/p)) (define letters/p (do (text <- (many/p letter/p)) (pure (list->string text)))) (define (bag/p str) (do (q <- letters/p) space*/p (n <- letters/p) space*/p (string/p str) space*/p (pure (bag (string-append q " " n))))) (define scalar-bag/p (do (scalar <- integer/p) space*/p (bag <- (bag/p (if (scalar . > . 1) "bags" "bag"))) (pure (cons scalar bag)))) (define sep/p (do (char/p #\,) space*/p)) (define no-bags/p (do (string/p "no other bags") (pure (list)))) (define rule/p (do (bag <- (bag/p "bags")) (string/p "contain") space*/p (items <- (or/p no-bags/p (many/p scalar-bag/p #:sep sep/p))) (char/p #\.) (pure (rule bag items)))) (define (parse s) (parse-result! (parse-string rule/p s))) (define (rules->hash rules) (define (f a s) (match a [(rule bag items) (hash-set s bag (rule bag items))])) (foldr f (hash) rules)) (define-runtime-path file "day7.txt") (define rs (file->lines file)) (define h (map parse rs)) (define h* (rules->hash h)) (define b (bag "shiny gold")) (count (λ (x) x) (map (λ (rule) (can-hold-bag b h* rule)) h)) (count-bags b h*)
false
6ba1260550e4cb7b7ac3881599545df6eeaac8ef
40dc3d2a08486f1440392517fd2cbf02757925ae
/doc/documentation.scrbl
b5dc1a60bd4f6f5943f78e44e7e064685202334c
[]
no_license
xingyif/racket-spark-light
50530b68367e5452a79420ea74aa45f5cae76096
e762e7c45d98c810435fcf00b64a9a22342eaf05
refs/heads/master
2021-04-29T18:28:47.572283
2018-04-22T02:43:48
2018-04-22T02:43:48
121,693,969
2
1
null
null
null
null
UTF-8
Racket
false
false
6,196
scrbl
documentation.scrbl
#lang scribble/manual @title{Racket Spark Light Documentation} This section will expain each available feature in RSL. @; ------------------------------------------------------------------------ @;table-of-contents[] @include-section["getting-started.scrbl"] @include-section["rsl.scrbl"] @section{Grammar} @(racketgrammar* [Program Top-Level ...] [Top-Level Definition Expr] [Definition (define Id RExpr) (define-rsl-func (Id Id) RExpr)] [Expr RExpr TExpr] [RExpr RacketExpressions] [TExpr Datashell Transformation Reduction] [TFunc Id] ;; that references a TFunc defined with define-rsl-func [AFunc (lambda (Id Id) Expr)] [FilePath String] [Datashell (mk-datashell [Listof Any]) (mk-datashell FilePath) Transformation] [Transformation (ds-map TFunc DataShell) (ds-filter TFunc Datashell)] [Reduction (ds-reduce AFunc Expr Datashell) (ds-collect Datashell) (ds-count Datashell) (ds-take-n Datashell num)]) A RacketExpression is any expression valid in #lang racket. @section{Creating A Datashell} A @bold{Datashell} is an immutable structure that stores user inputted lists of data, on which RSL Operations are performed. You will able to create a Datashell with the following functions: @defform[(mk-datashell l) #:contracts([l list?])]{ Creates a Datashell from the given list. } Example: @racketblock[(define a (mk-datashell '(5 2)))] @defform[(mk-datashell path) #:contracts([path String?])]{ Creates a Datashell from the given csv file path. } Example: @racketblock[(define csv-a (mk-datashell "../path-to-file.csv"))] @para{All Transformation Functions (TFuncs) take one input, and have one output} @section{Transformations} @subsection{Defining Transformation Functions} Transformations onto a Datashell are @bold{lazily} evaluated. A Transformation function provides a mapping from one item to another item. @defform[(define-rsl-func (name arg) body) #:contracts([name Id?] [arg Id?] [body Expr?])]{ Creates a transformation function which can be passed into @bold{ds-map} or @bold{ds-filter}. Note again that @bold{define-map-func} only takes one input argument and produces one output. @para{@bold{Effects (such as print statements) will not occur until the Datashell this TFunc is applied to is passed to a Reduction.}} } Example: @racketblock[ (define-rsl-func (sub-8 z) (- z 8)) (define-rsl-func (is-even num) (= (modulo num 2) 0)) ] @subsection{Mapping Transformation Functions} When called on a Datashell, transformations are queued up for later execution. These transformations will not execute until a Reduction is called on the Datashell. This allow RSL to evaluate all transformations applied to the Datashell in one iteration. @defform[(ds-map tfunc datashell) #:contracts([tfunc tfunc?] [datashell Datashell?])]{ Creates a new Datashell using the given Datashell mapped with the given function. The given procedure is not evaluated until a reduction is executed. } Example: @racketblock[ (define-rsl-func (sub-8 z) (- z 8)) (define b (ds-map sub-8 (mk-datashell '(50 20 49)))) b >'(42 12 41)] @defform[(ds-filter tfunc datashell) #:contracts([tfunc tfunc?] [datashell Datashell?])]{ Creates a new Datashell using the given Datashell filtered with the given predicate function. The given procedure is not evaluated until a reduction is executed. } Example: @racketblock[ (define-rsl-func (length-greater-than-3? l) (> (length l) 3)) (define filtered (ds-filter length-greater-than-3? (mk-datashell '((list 1 2 5 6) (list 1 2) (list 3 6 2 9 0))))) filtered >'((list 1 2 5 6) (list 3 6 2 9 0))] @section{Reductions/Actions} Reductions are @bold{eagerly} evaluated. A Reduction immediatly triggers the evaluation of the datashell's queued transformation(s), and it reduces the transformed dataset into a value to return to the user. @defform[(ds-reduce afunc base datashell) #:contracts([afunc Procedure?] [base Any?] [datashell Datashell?])]{ Applies the datashell's queued transformations then immediatly evaluates and returns the result of the reduction function on the datashell. The return type of @bold{ds-reduce} can be any except a Datashell. The return type of ds-reduce is the same as the type of @bold{base}, and the return type of @bold{afunc}. } Example: @racketblock[ (define a (mk-datashell '(1 2 3 4 5 6 7 8 9 10))) (ds-reduce + 0 a) > 55 ] @subsection{Library Reductions} @defform[(ds-collect datashell) #:contracts([datashell Datashell?])]{ Returns a list from the given datashell by applying all the datashell's queued functions and immediatly collecting the results. @bold{ds-collect} returns a [Listof Any]. } Example: @racketblock[ (define a2 (ds-filter mult-10 (ds-map less-than-5? (mk-datashell '(1 2 3 4 5 6 7 8 9 10))))) (define abcd2 (ds-filter multiple-of-20? a2)) (ds-collect abcd2) > (list 20 40) ] @defform[(ds-count datashell) #:contracts([datashell Datashell?])]{ Counts the number of items in the list after all transformations and filters have been applied. @bold{ds-collect} returns a Number. } Example: @racketblock[ (define a2 (ds-map mult-10 (ds-filter less-than-5? (mk-datashell '(1 2 3 4 5 6 7 8 9 10))))) (define abcd2 (ds-filter multiple-of-20? a2)) (ds-count abcd2) > 2 ] @defform[(ds-take-n datashell num) #:contracts([datashell Datashell?] [num Integer?])]{ Gets the first n items in the list after all transformations and filters have been applied. @bold{ds-collect} returns a [Listof Any] of at most n items. } Example: @racketblock[ (define a2 (ds-filter even-num? (ds-map mult-5 (mk-datashell '(1 2 3 4 5 6 7 8 9 10))))) (ds-take-n abcd2 3) > '(10 20 30) ]
false
63dd725f00097d739a850d1946311a69e09ec3f9
78fa8c4f6a73506ca5c8eb7768fe3377fcda75d6
/planet/terrain/terrain-structs.rkt
b3e78b755152f023b938728c6a5de6a2a33fa4e2
[]
no_license
data-navigator/earthgen
013194a4f39b120f2a763e90df61c5c910215e21
77fd85b4876bd541c20f61f37b22626ba9f65037
refs/heads/master
2021-06-08T18:28:25.880813
2016-11-05T22:57:29
2016-11-05T22:57:29
null
0
0
null
null
null
null
UTF-8
Racket
false
false
821
rkt
terrain-structs.rkt
#lang typed/racket (require vraid/struct "../direct-access.rkt" "../geometry/geometry-structs.rkt") (provide (all-defined-out)) (struct/kw terrain-parameters ([algorithm : Any] [seed : String] [grid-size : Integer] [radius : Float] [sea-level : Float] [axis : FlVector])) (vector-struct tile-terrain-data ([elevation : Float])) (vector-struct corner-terrain-data ([elevation : Float])) (struct/kw planet-terrain planet-geometry ([tile : tile-terrain-data] [corner : corner-terrain-data])) (direct-access planet-terrain tile tile-terrain-data ([elevation Float])) (direct-access planet-terrain corner corner-terrain-data ([elevation Float]))
false
a6b88f269926d887586af914f7501f1e6e14a0fb
a81d1aca1fdfd0f55282081a27d47478ec128902
/model/ext/lang/reader.rkt
1840376448d3d076ef9bf469577b4fc89d858809
[ "MIT" ]
permissive
intfrr/racket-algebraic
9eb4ca7ba87db188f6c92580fdbf5f75af0b297d
399a3945d736f8a5021bbc15c9bd6148e06a0d3e
refs/heads/master
2020-05-05T12:17:24.632718
2019-04-01T01:14:31
2019-04-01T01:14:31
null
0
0
null
null
null
null
UTF-8
Racket
false
false
53
rkt
reader.rkt
#lang s-exp syntax/module-reader algebraic/model/ext
false
4e9c8e3d5118fe1e2d3a6068beb9dafef2a6e07b
360dceff10ce0671c4f5177ce1271bb760ff38f1
/mosaic/model.rkt
fc967fb563186b2d711ac5bdea384c817602c829
[]
no_license
shunsunsun/mosaic-racket
7893f296978a240890d671821ea9c869e7239bd0
0e5adfe634e540f2cf4af42cd9d267e33dfca156
refs/heads/master
2021-08-27T15:15:51.352815
2014-04-10T14:48:07
2014-04-10T16:21:40
null
0
0
null
null
null
null
UTF-8
Racket
false
false
12,160
rkt
model.rkt
#lang racket (provide atom-descr fragment-descr polymer-descr node atom fragment universe configuration make-fragment make-universe make-configuration make-data-item define-fragment define-polymer Ac Ag Al Am Ar As At Au B Ba Be Bh Bi Bk Br C Ca Cd Ce Cf Cl Cm Co Cn Cr Cs Cu D Db Ds Dy Er Es Eu F Fe Fm Fr Ga Gd Ge H He Hf Hg Ho Hs I In Ir K Kr La Li Lr Lu Md Mg Mn Mo Mt N Na Nb Nd Ne Ni No Np O Os P Pa Pb Pd Pm Po Pr Pt Pu Ra Rb Re Rf Rg Rh Rn Ru S Sb Sc Se Sg Si Sm Sn Sr Ta Tb Tc Te Th Ti Tl Tm U V W Xe Y Yb Zn Zr) (require (prefix-in interface: "interface.rkt") (for-syntax syntax/parse) math/array generic-bind) ; Atom and Fragment descriptors (struct atom-descr (type name) #:transparent) (define (~frag-wrapper fn) (lambda (fragment-descr . args) (apply fn (fragment "_" fragment-descr) args))) (struct fragment-descr (species subfragments atoms bonds) #:transparent #:methods gen:dict [(define dict-ref (~frag-wrapper interface:fragment-dict-ref)) (define dict-count (~frag-wrapper interface:fragment-dict-count)) (define dict-iterate-first (~frag-wrapper interface:fragment-dict-iterate-first)) (define dict-iterate-next (~frag-wrapper interface:fragment-dict-iterate-next)) (define dict-iterate-key (~frag-wrapper interface:fragment-dict-iterate-key)) (define dict-iterate-value (~frag-wrapper interface:fragment-dict-iterate-value))]) (struct polymer-descr (type species subfragments bonds) #:transparent #:methods gen:dict [(define dict-ref (~frag-wrapper interface:fragment-dict-ref)) (define dict-count (~frag-wrapper interface:fragment-dict-count)) (define dict-iterate-first (~frag-wrapper interface:fragment-dict-iterate-first)) (define dict-iterate-next (~frag-wrapper interface:fragment-dict-iterate-next)) (define dict-iterate-key (~frag-wrapper interface:fragment-dict-iterate-key)) (define dict-iterate-value (~frag-wrapper interface:fragment-dict-iterate-value))]) ; Atoms and fragments (struct node (label) #:transparent #:methods interface:gen:node [(define (node.label atom) (node-label atom))]) (struct atom node (adescr nsites) #:transparent #:methods interface:gen:atom [(define (atom.type atom) (let ([t (atom-descr-type (atom-adescr atom))]) (if (equal? t 'unknown) "" (symbol->string t)))) (define (atom.name atom) (atom-descr-name (atom-adescr atom))) (define (atom.nsites atom) (atom-nsites atom))] #:methods gen:custom-write [(define (write-proc atom port mode) (write-string "<atom " port) (write-string (node-label atom) port) (write-string ">" port))]) (define (make-atom a) (atom (interface:node.label a) (atom-descr (let ([t (interface:atom.type a)]) (if (string=? t "") 'unknown (string->symbol t))) (interface:atom.name a)) (interface:atom.nsites a))) (struct fragment node (fdescr) #:transparent #:methods interface:gen:fragment [(define (fragment.species fragment) (let ([fd (fragment-fdescr fragment)]) (if (polymer-descr? fd) (polymer-descr-species fd) (fragment-descr-species fd)))) (define (fragment.subfragments fragment) (let ([fd (fragment-fdescr fragment)]) (if (polymer-descr? fd) (polymer-descr-subfragments fd) (fragment-descr-subfragments fd)))) (define (fragment.atoms fragment) (let ([fd (fragment-fdescr fragment)]) (if (polymer-descr? fd) '() (fragment-descr-atoms fd)))) (define fragment.lookup-node interface:fragment-lookup-node) (define (fragment.bonds fragment) (map (lambda (b) (match-let* ([(list a1 a2) (set->list (car b))] [order (cdr b)] [m-order (if (equal? order 'unknown) "" (symbol->string order))]) (if (string<? a1 a2) (vector-immutable a1 a2 m-order) (vector-immutable a2 a1 m-order)))) (set->list (let ([fd (fragment-fdescr fragment)]) (if (polymer-descr? fd) (polymer-descr-bonds fd) (fragment-descr-bonds fd)))))) (define (fragment.polymer? fragment) (polymer-descr? (fragment-fdescr fragment))) (define (fragment.polymer-type fragment) (symbol->string (polymer-descr-type (~get-polymer-descr fragment))))] #:methods gen:dict [(define dict-ref interface:fragment-dict-ref) (define dict-count interface:fragment-dict-count) (define dict-iterate-first interface:fragment-dict-iterate-first) (define dict-iterate-next interface:fragment-dict-iterate-next) (define dict-iterate-key interface:fragment-dict-iterate-key) (define dict-iterate-value interface:fragment-dict-iterate-value)] #:methods gen:stream [(define (stream-empty? fragment) (empty? (polymer-descr-subfragments (~get-polymer-descr fragment)))) (define (stream-first fragment) (first (polymer-descr-subfragments (~get-polymer-descr fragment)))) (define (stream-rest fragment) (rest (polymer-descr-subfragments (~get-polymer-descr fragment))))] #:methods gen:custom-write [(define (write-proc fragment port mode) (write-string (if (polymer-descr? (fragment-fdescr fragment)) "<polymer " "<fragment ") port) (write-string (node-label fragment) port) (write-string ">" port))]) (define (~get-polymer-descr fragment) (let ([fd (fragment-fdescr fragment)]) (if (polymer-descr? fd) fd (raise-argument-error 'fragment.polymer-type "fragment.polymer?" fragment)))) (define (make-fragment f) (let ([species (interface:fragment.species f)] [subfragments (map make-fragment (interface:fragment.subfragments f))] [atoms (map make-atom (interface:fragment.atoms f))] [bonds (list->set (map (λ (b) (cons (set (vector-ref b 0) (vector-ref b 1)) (string->symbol (vector-ref b 2)))) (interface:fragment.bonds f)))]) (fragment (interface:node.label f) (if (interface:fragment.polymer? f) (polymer-descr (string->symbol (interface:fragment.polymer-type f)) species subfragments bonds) (fragment-descr species subfragments atoms bonds))))) ; Universe (struct universe (cell-shape symmetry-transformations convention molecules) #:transparent #:methods interface:gen:universe [(define (universe.cell-shape universe) (symbol->string (universe-cell-shape universe))) (define (universe.symmetry-transformations universe) (universe-symmetry-transformations universe)) (define (universe.convention universe) (universe-convention universe)) (define (universe.molecules universe) (universe-molecules universe))] #:methods gen:custom-write [(define (write-proc universe port mode) (write-string "<" port) (write-string (symbol->string (universe-cell-shape universe)) port) (write-string " universe>" port))]) (define (make-universe u) (universe (string->symbol (interface:universe.cell-shape u)) (interface:universe.symmetry-transformations u) (interface:universe.convention u) (~for/list ([($: fragment count) (interface:universe.molecules u)]) (cons (make-fragment fragment) count)))) ; Macros for conveniently defining atoms and fragments (define-syntax-rule (define-element symbol) (define symbol (atom-descr 'element (symbol->string (quote symbol))))) (define-syntax define-elements (syntax-rules () [(define-elements s) (define s (atom-descr 'element (symbol->string (quote s))))] [(define-elements s1 s2 ...) (begin (define-element s1) (define-elements s2 ...))])) (define-elements Ac Ag Al Am Ar As At Au B Ba Be Bh Bi Bk Br C Ca Cd Ce Cf Cl Cm Co Cn Cr Cs Cu D Db Ds Dy Er Es Eu F Fe Fm Fr Ga Gd Ge H He Hf Hg Ho Hs I In Ir K Kr La Li Lr Lu Md Mg Mn Mo Mt N Na Nb Nd Ne Ni No Np O Os P Pa Pb Pd Pm Po Pr Pt Pu Ra Rb Re Rf Rg Rh Rn Ru S Sb Sc Se Sg Si Sm Sn Sr Ta Tb Tc Te Th Ti Tl Tm U V W Xe Y Yb Zn Zr) (begin-for-syntax (define-syntax-class atom-spec #:description "atom specification" (pattern (label:expr atom-descr:expr) #:with spec #'(atom label atom-descr 1)) (pattern (label:expr atom-descr:expr nsites:expr) #:with spec #'(atom label atom-descr nsites))) (define-syntax-class fragment-spec #:description "fragment specification" (pattern (label:expr fragment-descr:expr) #:with spec #'(fragment label fragment-descr))) (define-syntax-class bond-spec #:description "bond specification" (pattern (atom1:expr atom2:expr) #:with spec #'(cons (set atom1 atom2) 'unknown)) (pattern (atom1:expr atom2:expr order:expr) #:with spec #'(cons (set atom1 atom2) order)))) (define-syntax (define-fragment stx) (syntax-parse stx [(define-fragment species (~optional (~seq #:subfragments (frag:fragment-spec ...))) (~optional (~seq #:atoms (atom:atom-spec ...))) (~optional (~seq #:bonds (bond:bond-spec ...)))) (with-syntax ([species-str (symbol->string (syntax->datum #'species))] [frag (or (attribute frag.spec) '())] [atom (or (attribute atom.spec) '())] [bond (or (attribute bond.spec) '())]) #'(define species (fragment-descr species-str (list . frag) (list . atom) (set . bond))))])) (define-syntax (define-polymer stx) (syntax-parse stx [(define-polymer species polymer-type (~optional (~seq #:subfragments (frag:fragment-spec ...))) (~optional (~seq #:bonds (bond:bond-spec ...)))) (with-syntax ([species-str (symbol->string (syntax->datum #'species))] [frag (or (attribute frag.spec) '())] [bond (or (attribute bond.spec) '())]) #'(define species (polymer-descr polymer-type species-str (list . frag) (set . bond))))])) ; Configurations (struct configuration (universe positions cell-parameters number-type) #:transparent #:methods interface:gen:configuration [(define (configuration.universe configuration) (configuration-universe configuration)) (define (configuration.positions configuration) (configuration-positions configuration)) (define (configuration.cell-parameters configuration) (configuration-cell-parameters configuration)) (define (configuration.number-type configuration) (symbol->string (configuration-number-type configuration)))]) (define (make-configuration c) (configuration (make-universe (interface:configuration.universe c)) (interface:configuration.positions c) (interface:configuration.cell-parameters c) (string->symbol (interface:configuration.number-type c)))) ; Generic factory function (define (make-data-item d) (cond [(interface:universe? d) (make-universe d)] [(interface:configuration? d) (make-configuration d)] [else (error "not a Mosaic data item")]))
true
337d35ce2a43ddf2fc72ed0c573c7776a23d3a10
099418d7d7ca2211dfbecd0b879d84c703d1b964
/whalesong/lang/js/query.rkt
af9d9cbd5eb6a9c7656c74fd9012f61272c22174
[]
no_license
vishesh/whalesong
f6edd848fc666993d68983618f9941dd298c1edd
507dad908d1f15bf8fe25dd98c2b47445df9cac5
refs/heads/master
2021-01-12T21:36:54.312489
2015-08-19T19:28:25
2015-08-19T20:34:55
34,933,778
3
0
null
2015-05-02T03:04:54
2015-05-02T03:04:54
null
UTF-8
Racket
false
false
3,015
rkt
query.rkt
#lang racket/base (require racket/contract racket/runtime-path ;; racket/gui/base syntax/modresolve) (provide/contract [query (module-path? . -> . (listof string?))] [has-javascript-implementation? (module-path? . -> . boolean?)] [redirected? (path? . -> . boolean?)] [follow-redirection (path? . -> . path?)] [collect-redirections-to (path? . -> . (listof path?))] [lookup-module-requires (path? . -> . (listof path?))]) (define-runtime-path record.rkt "record.rkt") (define ns (make-base-namespace)) (define (my-resolve-module-path a-module-path) (resolve-module-path a-module-path #f)) ;; query: module-path -> string? ;; Given a module, see if it's implemented via Javascript. (define (query a-module-path) (let ([resolved-path (my-resolve-module-path a-module-path)]) (parameterize ([current-namespace ns]) (dynamic-require resolved-path (void)) ;; get the compile-time code running. ((dynamic-require-for-syntax record.rkt 'lookup-javascript-implementation) resolved-path)))) ;; has-javascript-implementation?: module-path -> boolean (define (has-javascript-implementation? a-module-path) (let ([resolved-path (my-resolve-module-path a-module-path)]) (parameterize ([current-namespace ns]) (dynamic-require resolved-path (void)) ;; get the compile-time code running. ((dynamic-require-for-syntax record.rkt 'has-javascript-implementation?) resolved-path)))) ;; redirected? path -> boolean (define (redirected? a-module-path) (let ([resolved-path (my-resolve-module-path a-module-path)]) (parameterize ([current-namespace ns]) (dynamic-require resolved-path (void)) ;; get the compile-time code running. (path? ((dynamic-require-for-syntax record.rkt 'follow-redirection) resolved-path))))) ;; follow-redirection: module-path -> path (define (follow-redirection a-module-path) (let ([resolved-path (my-resolve-module-path a-module-path)]) (parameterize ([current-namespace ns]) (dynamic-require resolved-path (void)) ;; get the compile-time code running. ((dynamic-require-for-syntax record.rkt 'follow-redirection) resolved-path)))) ;; collect-redirections-to: module-path -> (listof path) (define (collect-redirections-to a-module-path) (let ([resolved-path (my-resolve-module-path a-module-path)]) (parameterize ([current-namespace ns]) (dynamic-require resolved-path (void)) ;; get the compile-time code running. ((dynamic-require-for-syntax record.rkt 'collect-redirections-to) resolved-path)))) (define (lookup-module-requires a-module-path) (let ([resolved-path (my-resolve-module-path a-module-path)]) (parameterize ([current-namespace ns]) (dynamic-require resolved-path (void)) ;; get the compile-time code running. ((dynamic-require-for-syntax record.rkt 'lookup-module-requires) resolved-path))))
false
b8bfea999758c53f1086bdcfee7f176163b42ff3
d0815b834f03a1fa9b4833b4dcaaa5fab0088fe6
/app-name-here/components/url.rkt
fd01ebda0f0acdda435e76627e7d2ce3f08bfa8a
[ "BSD-3-Clause" ]
permissive
Bogdanp/racket-webapp-template
4da21c20e77641a86fccbf1ab1353167b069786c
83bc1b9cb62783d54882f823b7c6a9fe8ad41d3b
refs/heads/master
2020-04-18T09:34:19.556012
2019-06-02T10:35:05
2019-06-02T10:35:05
167,438,891
2
0
null
null
null
null
UTF-8
Racket
false
false
1,217
rkt
url.rkt
#lang racket/base (require net/url racket/contract racket/function (prefix-in config: "../config.rkt")) ;; application urls ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (provide make-application-url) (define/contract (make-application-url #:query [query null] #:fragment [fragment #f] . path-elements) (() (#:query (listof (cons/c symbol? string?)) #:fragment (or/c false/c string?)) #:rest (listof string?) . ->* . string?) (define path (map (curryr path/param null) path-elements)) (define port (cond [(member config:url-port '("80" "443")) #f] [else (string->number config:url-port)])) (url->string (url config:url-scheme #f config:url-host port #t path query fragment))) ;; reverse uris ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (provide current-reverse-uri-fn reverse-uri) (define/contract current-reverse-uri-fn (parameter/c (-> symbol? any/c ... string?)) (make-parameter (lambda args (error "current-reverse-uri-fn not installed")))) (define (reverse-uri . args) (apply (current-reverse-uri-fn) args))
false
2c9dce11aaa856317ab273f7494e80c49408f875
0884f0d8c2cd37d8e3a6687e462862e4063b9aa4
/src/style-guide.scrbl
310da5a3cef8e99596939520c123a0331e83cea9
[]
no_license
brownplt/pyret-docs
988becc73f149cbf2d14493c05d6f2f42e622130
6d85789a995abf8f6375cc7516406987315972d1
refs/heads/horizon
2023-08-17T03:32:51.329554
2023-08-10T20:44:14
2023-08-10T20:44:14
61,943,313
14
20
null
2023-09-12T20:40:41
2016-06-25T12:57:24
Racket
UTF-8
Racket
false
false
9,380
scrbl
style-guide.scrbl
#lang scribble/base @(define code tt) @(define codedisp verbatim) @title{Pyret Style Guide} @author{Frank Goodman and Shriram Krishnamurthi} Ahoy matey! Here be the style guide for Pyret. Follow me rules to find the hidden treasure, or walk the plank! @(table-of-contents) @section{General} @subsection{Indentation} You should indent your code blocks using two spaces (not tabs). @subsection{Line Length} Try to keep the total length of your lines under 100 characters. For overly long lines, it's actually really hard to figure out where to put in good line breaks. This is in every language. Look for something that tries to match the logical structure of your program. However, there's usually a better way to solve this problem: create extra variables to name the intermediate pieces, and use those names. E.g.: instead of worrying where to put in line breaks in @codedisp{ fun f(x, y, z): g(some-very-long-thing(x * x, y + y), other-very-long-thing((x + y + z) / (2 * 3 * 4))) end } it might be better to write it as @codedisp{ fun f(x, y, z): sensible-name-1 = some-very-long-thing(x * x, y + y) sensible-name-2 = other-very-long-thing((x + y + z) / (2 * 3 * 4)) g(sensible-name-1, sensible-name-2) end } (and think about indenting/shortening those two new lines). Not only does this shorten lines, it makes it clearer what all these pieces are doing, helping a later reader (who may be yourself!). @subsection{Variable Naming} The programming language world rages about the use of @code{camelCase} versus @code{under_scores} in variable names. Pyret's syntax supports both, but we can do better. In Pyret, you can use dashes (@code{-}) inside variable names.@margin-note*{This is sometimes called ``kebab case'', but it would be more accurate to call it ``shish case''.} Thus, you would write @code{camel-case} and @code{under-scores}. Unlike underscores, dashes don't need a shift key (or disappear when text is underlined by an environment). Unlike camelcase, dashes don't create ambiguities (what if one of the words is in all-caps?). Dashes are also humanizing: they make your program look that little bit more like human prose. Most languages can't support dashes because the dash also stands for infix subtraction. In Pyret, subtraction must be surrounded by space. Therefore, @code{camel-case} is a name whereas @code{camel - case} is subtraction. @subsubsection{Naming Constants} You should name constants in all-capital letters unless an external convention would dictate using some other capitalization for that particular name. For example, @codedisp{ MY-COUNT = 100 e = 2.7182 } @subsubsection{Reusing Variable Names} Pyret is picky about letting you reuse variable names. This is to help you avoid confusing two different variables that have the same name and accidentally using the wrong one. Specifically, an inner scope can't use a name that is already bound in an outer scope; but two different inner scopes can each use the same name. For instance, @codedisp{ fun f(x): x + 1 end fun g(x): x + 2 end } is legal, but @codedisp{ fun h(x): x = 4 x + 1 end } is not. @subsection{File Naming} Use @code{.arr} as the extension for Pyret files. @subsection[#:tag "eg-tests"]{Example and Tests} We use the syntax of testing to represent two different tasks: @emph{examples}, which help us explore a problem and take steps towards deriving a solution, and @emph{tests}, which are designed to find errors. These are subtly different. We write (most) examples @emph{before} writing the corresponding code. Therefore, it makes sense to put these examples in an @code{examples} block: @codedisp{ examples: f(10) is 25 f(20) is-not 2000 end } The keyword @code{examples} is synonymous with @code{check}, so we could as well have written @code{check} instead. However, by convention we use @code{check} for tests rather than examples. @section{Functions} @subsection{Naming} Give functions descriptive names. Do the same for arguments. That way, a quick scan of a function's header will tell you what it does and what the arguments are supposed to do. @subsection{Documentation Strings} Unless the name is self-evident, write a brief documentation string for your function. For instance: @codedisp{ fun insert(x, l): doc: "consumes sorted list l; returns it with x in the right place" ... end } Try to write your documentation in functional form, i.e., describing what the function consumes and what it returns after computation. If your comment needs to span multiple lines, use three back-ticks--- @codedisp{ ``` } ---to begin and end the string. For instance: @codedisp{ fun f(x): doc: ```This is a multi-line comment here.``` x + x end } This is also how you write a multi-line string in Pyret. @subsection{Annotations} Wherever possible, annotate both argument and return values. For instance, @codedisp{ fun str-len(str :: String) -> Number: # ... end } Even though Pyret does not currently check parametric annotations, you should still write them for their value as user documentation. Thus: @codedisp{ fun length(lst :: List<Any>) -> Number: # ... end } You can even write an arbitrary predicate when a built-in annotation isn't expressive enough. For instance, suppose we want to write a function that consumes only non-negative numbers. We can define the predicate--- @codedisp{ fun non-negative(n :: Number) -> Boolean: n >= 0 end } and then use it as follows: @codedisp{ fun sqrt(n :: Number%(non-negative)) -> Number: # ... end } @subsection{Testing} You should test every function you write for both general cases and edge cases. As we have discussed earlier [@secref["eg-tests"]], you can write these using @code{examples} and @code{check}. In addition, you can also write examples and tests of functions as part of the function declaration, using @code{where}: @codedisp{ fun double(n :: Number) -> Number: n * 2 where: double(0) is 0 double(5) is 10 double(-5) is -10 double(100) is 200 double(-100) is -200 end } Usually, the examples you create to help you think through the problem would go in an @code{examples} block, and a large suite of tests would end up in a separate @code{check} block. In a @code{where} block, we should have a small number of @emph{illustrative} examples that help a reader to quickly grasp the essence of the function's behavior. Try to keep the size of the @code{where} block small and manageable. In particular, a large test suite---meant to cover lots of behaviors, including potentially redundant ones, and to find bugs---should go in a separate @code{check} block rather than cluttering up the function definition's @code{where} region. @section{Data} @subsection{Definitions} Wherever possible, provide annotations in Data definitions: @codedisp{ data Animal: | snake(name :: String) | dillo(weight :: Number, living :: Boolean) end } @subsection{Cases} To branch on the variants of a datum, use @code{cases}: @codedisp{ cases (Animal) a: | snake(s) => s == "Dewey" | dillo(w, l) => (w < 10) and l end } Sometimes, you won't use all the parts of a datum. You can still name an unused part, but it is suggestive to use @code{_} instead; this indicates to the reader that that field won't be used in this computation, so they can ignore it: @codedisp{ cases (Animal) a: | snake(s) => ... | dillo(w, _) => ... end } Note that @code{_} is different from identifier names like @code{dummy} because you can't write @codedisp{ cases (Animal) a: | snake(s) => ... | dillo(dummy, dummy) => ... end } (you'll get an error because you're trying to bind @code{dummy} twice), but you can write @codedisp{ cases (Animal) a: | snake(s) => ... | dillo(_, _) => ... end } and thus ignore multiple fields. Finally, if your conditional is not designed to handle a particular kind of datum, signal an error: @codedisp{ cases (Animal) a: | snake(s) => ... | dillo(_, _) => raise("Serpents only, please!") end } @section{Naming Intermediate Expressions} @subsection{Local Variables} You are welcome to create local names for expressions. For instance, instead of writing @codedisp{ fun hypo-len(a, b): num-sqrt((a * a) + (b * b)) end } you are welcome to write @codedisp{ fun hypo-len(a, b): a2 = a * a b2 = b * b sum-of-other-two-sides = a2 + b2 num-sqrt(sum-of-other-two-sides) end } Even though you shouldn't have multiple @emph{expressions} as a function body, these local definitions are not expressions in their own right, so this is perfectly legal code; the value of calling the function is that produced by its expression (which, here, is @code{num-sqrt(sum-of-other-two-sides)}). @subsection{Beware of @code{var}!} You might have noticed that Pyret lets you write @code{var} before local names: for instance, you can write the previous example as @codedisp{ fun hypo-len(a, b): var a2 = a * a var b2 = b * b var sum-of-other-two-sides = a2 + b2 num-sqrt(sum-of-other-two-sides) end } instead. In particular, if you have prior experience in a language like JavaScript, you might think this is @emph{good} practice. It's not: @emph{don't do this}! In Pyret, adding @code{var} turns each name into a @emph{mutable variable}, i.e., one that you can modify using an assignment statement. Therefore, do not use @code{var} unless you absolutely mean to create a mutable variable.
false
012882fba61e1f68c0b7d2bad1f0b34db3106c63
45097afbbd28e22aa4d184e73368024e1024037f
/beautiful-racket/jsonic/my-test.rkt
91ba2102ffad573df493799068163b54e7ff9b6f
[ "MIT" ]
permissive
nadeemabdulhamid/racket-summer-school-2017
fff166ad8b44d9d447118b289e85ea9f56883334
e09b35df9391b313da27d1d15cb92120ca2836ff
refs/heads/master
2020-04-03T14:04:59.573791
2017-07-04T07:53:02
2017-07-04T07:53:02
95,151,672
0
0
null
null
null
null
UTF-8
Racket
false
false
274
rkt
my-test.rkt
#lang jsonic { "name" : "Nadeem", // full name "yob" : @$ (+ 1900 77) $@, "data" : [ null, @$ (string-append "41" ; ignore this racket comment (substring (number->string (exact->inexact (/ 4 10))) 1)) $@, true, @$ "test" $@ ] } // good
false
2a22fb304a957389d6778e70ffbb542cfac0a4d3
6582bfe2990716ee85fb69338aebf1abaa158bc0
/brag-lib/brag/test/test-hide-and-splice.rkt
17d19e489ca9feae05a0c6f0719ef16727879b7f
[ "MIT" ]
permissive
mbutterick/brag
2a3962b8d4ed80488812caae870b852a44c247d8
f52c2a80c9cb6840b96532c2ca1371d12aea61e7
refs/heads/master
2022-06-03T00:15:21.317870
2022-02-09T18:04:04
2022-02-09T18:04:04
82,710,347
67
15
MIT
2022-03-16T01:04:27
2017-02-21T17:57:12
Racket
UTF-8
Racket
false
false
284
rkt
test-hide-and-splice.rkt
#lang racket/base (require brag/examples/hide-and-splice brag/support rackunit) ;; check that an id with both a splice and hide is handled correctly (check-equal? (parse-to-datum "xxx") '(top ("x" "x" "x"))) (check-equal? (parse-to-datum "yyy") '(top "y" "y" "y"))
false
3f848557daea8d1553b3d1f47d92595a8fb14c42
0522d9c9396704f95af5ba939df6e7c118d34858
/control/fixpoint.rkt
0cb722c596dbe8671440d6f9670933be1bebaafe
[ "Apache-2.0" ]
permissive
noti0na1/Racket-Codes
f04a25f80d1614a891d3d4446efd4388d21ceabe
e7d572700f803cef917d20b9975873311181d924
refs/heads/master
2021-01-23T15:52:15.743929
2017-09-18T06:51:41
2017-09-18T06:51:41
93,274,293
1
0
null
null
null
null
UTF-8
Racket
false
false
228
rkt
fixpoint.rkt
#lang racket (define rec (λ (f) ((λ (x) (λ a (apply (f (x x)) a))) (λ (x) (λ a (apply (f (x x)) a)))))) (define fun (rec (λ (fun) (λ (x) (if (= x 0) 1 (* x (fun (- x 1)))))))) (fun 10)
false
cc4826e9abd38d1764687e6ad9750aa7ebe35d05
657061c0feb2dcbff98ca7a41b4ac09fe575f8de
/Racket/Exercises/Week2/reverse_number.rkt
d067a9920c517efa2d9d720d2509e97f8fe0faea
[]
no_license
vasil-pashov/FunctionalProgramming
77ee7d9355329439cc8dd89b814395ffa0811975
bb998a5df7b715555d3272c3e39b0a7481acf80a
refs/heads/master
2021-09-07T19:31:05.031600
2018-02-27T20:50:44
2018-02-27T20:50:44
108,046,015
0
0
null
null
null
null
UTF-8
Racket
false
false
218
rkt
reverse_number.rkt
#lang racket ;Given a number reverse its digits (define (reverse n) (define (reverse* n res) (if (= n 0) res (reverse* (quotient n 10) (+ (* 10 res) (remainder n 10))) )) (reverse* n 0))
false
d2cf5f6dabae3e1ffae6c52dce4f0ff0304488fb
08515a0f79a475b3c6b4459c2b2f6067fd8fce1e
/Exams/Final Exam/Final Review Session Template.rkt
4b8dbdec78de84c1c05f2d0a08db1484863e7cf7
[]
no_license
AlbMej/CSE-1729-Introduction-to-Principles-of-Programming
ce15bcc716bdcdfe72f5e894f812df844c04d683
49acc5b34e54eb55bc32670ce87222d71e09f071
refs/heads/master
2021-06-12T05:48:37.728863
2021-04-25T05:08:56
2021-04-25T05:08:56
172,804,634
0
0
null
null
null
null
UTF-8
Racket
false
false
6,771
rkt
Final Review Session Template.rkt
; Quinn Vissak ; CSE 1729 Final Review Session ; December 7, 2017 ; McCartney's Exam: Wednesday, December 13th, 2017 @ 6:00pm - 8:00pm CAST 212 ; Johnson's Exam: Tuesday, December 12th, 2017 @ 1:00pm - 3:00pm PB 38 ; Brandon Cheng will be covering some content about trees/heaps in a ; separate document. ; Mutable Data ; Objects, Streams, and Vectors """ Implement a stack data structure with the following methods: (a) push - takes a parameter and puts it at the top of the stack. (b) pop - removes the top-most element and returns it. Return 'undefined on an empty stack. (c) peek - returns the top element (without removing it). (d) invert - reverses the stack order (top becomes bottom, etc.). (e) add - takes the 2 elements at the top of the stack, adds them, and pushes the result back onto the stack. (f) mult - takes the 2 elements at the top of the stack, multiplies them, and pushes the result back onto the stack. (g) sub - subtracts the top element of the stack from the 2nd most top element of the stack. Note: add, mult, sub should return the single element of a stack if the stack size is 1. Return 'undefined if the stack size is 0. """ "Testing stack data structure" """ A Priority Queue is like a Queue, however elements are sorted (descending order) by urgency. Each element is represented as a pair of two integers. The first integer is the priority and the second integer is the value. Implement a Priority Queue data structure with the following methods: (a) empty? - return true if the PQ is empty. (b) size - returns the size of the queue. (c) element? - which takes a priority and return true if there is some pair in the queue with that priority, false otherwise. (d) get-min - returns the minimum value of the queue. If empty, return 'undefined. (e) delete-min - deletes the element with the minimum value from the queue. Should not return. (f) delete - deletes an element x from the queue. (g) insert - inserts an element x into the queue so that the queue maintains its sorted order. Duplicate priorities are permitted. (h) order - prints the priority queue in memory. """ "Testing priority queue data structure" """ Implement a function k-power-stream that takes a parameter k and produces a stream of integers all raised to the kth power. """ (define-syntax cons-stream (syntax-rules () ((cons-stream head tail) (cons head (delay tail))))) (define (stream-car x) (car x)) (define (stream-cdr x) (force (cdr x))) (define empty-stream? null?) (define (ints-from a) (cons-stream a (ints-from (+ a 1)))) (define (enumerate-integer-stream) (ints-from 0)) ; helpful for testing (define (str-to-list str n) (cond ((or (empty-stream? str)(= n 0)) '()) (else (cons (stream-car str) (str-to-list (stream-cdr str) (- n 1)))))) "Testing k-power-stream" """ Implement a funtion add-pairs that takes a stream and returns a stream with adjacent pairs (non-repeating) added together. i.e '(1 2 3 4 5 6 ...) => '(3 7 11) """ "Testing add-pairs" """ Implement a function stride-pair that takes a stream and a value k. It creates a stream of pairs that contains elements with k distance between them from the original stream. i.e (stride-pair (ints-from 1) 4) => '((1 . 5) (2 . 6) (3. 7) (4. 8) ...) """ "Testing stride-pair" ; Note: vectors will not be on McCartney's exam ; However, they *might* be a subpart of a question on Johnson's exam ; Disclaimer: TAs have NOT seen the exam! """ Implement a stack data structure with vectors having the following methods: (a) empty? - returns true if the stack is empty, false otherwise. (b) push - adds an element to the top of the stack. No return value. (c) pop - remove an element from the top of the stack, return element. (d) peek - return top value on top of the stack. Do not remove. (e) size - return size of the stack. Note: position 0 in the vector is the *bottom* of your stack. """ "Testing vector" (define (new-account initial-balance password) (let ((balance initial-balance) (interestrate 0.01) (pw password)) (define (deposit f password) (cond ((equal? pw password) (begin (set! balance (+ balance f)) balance)))) (define (withdraw f password) (cond ((equal? pw password) (begin (set! balance (- balance f)) balance)))) (define (bal-inq password) (cond ((equal? pw password) balance) (else "wrong password hitta"))) (define (accrue) (begin (set! balance (+ balance (* balance 1 interestrate))) balance)) (define (setrate r) (set! interestrate r)) (define (change-password old new) (cond ((equal? old pw) (set! pw new)))) (lambda (method) (cond ((eq? method 'deposit) deposit) ((eq? method 'withdraw) withdraw) ((eq? method 'balance-inquire) bal-inq) ((eq? method 'accrue) accrue) ((eq? method 'setrate) setrate) ((eq? method 'change-pw) change-password))))) (define my-check (new-account 100 "pp")) ((my-check 'balance-inquire) "pp") (define (make-queue) (let ((head '()) (tail '())) (define (value n) (car n)) (define (next n) (cdr n)) (define (empty?) (null? head)) (define (front) (value head)) (define (enqueue x) (let ((new-node (cons x '()))) (begin (if (empty?) (set! head new-node) (set-cdr! tail new-node)) (set! tail new-node)))) ;(display (value head)) (display " | ") (display (next head)) (newline)))) (define (dequeue) (let ((return (value head))) (if (eq? head tail) (begin (set! head '()) (set! tail '()) return) (begin (set! head (next head)) return)))) (define (dispatcher method) (cond ((eq? method 'empty) empty?) ((eq? method 'enqueue) enqueue) ((eq? method 'dequeue) dequeue) ((eq? method 'front) front))) dispatcher)) (define q (make-queue)) ((q 'enqueue) 5) ((q 'enqueue) 6) ((q 'enqueue) 7) ((q 'dequeue)) ((q 'enqueue) 8) ((q 'dequeue)) ((q 'dequeue)) ((q 'dequeue)) ((q 'empty)) (define (bubble-up L) (if (null? (cdr L)) L (if (< (car L) (cadr L)) (cons (car L) (bubble-up (cdr L))) (cons (cadr L) (bubble-up (cons (car L) (cddr L))))))) (bubble-up '(5 10 9 8 7)) (define (bubble-sort-aux N L) (cond ((= N 1) (bubble-up L)) (else (bubble-sort-aux (- N 1) (bubble-up L))))) (define (bubbleH L) (bubble-sort-aux (length L) L)) (bubbleH '(5 10 9 8 7)) =
true
fdfa6bb2a30c8c5b586f0591be9b8b3257bd2648
a10b9011582079d783282e79e4cfdc93ace6f6d3
/exercises/11/01enum.rkt
7e332179dc1e73748da5f45cd55448a0c199a0dc
[]
no_license
hristozov/fpkn1415
2996a488c1feba6a595e466ca42a1418b03e2a77
9b44eb9c9ff4402ff22c2a5f55285c1f59b99722
refs/heads/master
2016-09-05T13:02:38.264241
2015-08-22T14:11:05
2015-08-22T14:11:05
24,793,324
11
1
null
null
null
null
UTF-8
Racket
false
false
191
rkt
01enum.rkt
#lang racket (require "../../lib/rkt/unit.rkt") (define (enum a b) (if (= a b) (stream b) (stream-cons a (enum (+ a 1) b)))) (assert-equal '(1 2 3) (stream->list (enum 1 3)))
false
d02a65f2e551cb60362f68d0f8c788463272f0b3
7970b387bf64da3cf7520a389fc2afca345dd820
/probability/match-hash-member.rkt
df601495457f682d82bfe86a6b8eb69f8276c6bd
[ "MIT" ]
permissive
AlexKnauth/probability
17c44436315e70b3d57cf18e9f00d9401d3f480e
85fa5ad445ce92d871bb0c763f3c832745e6a71d
refs/heads/master
2022-02-06T06:10:48.698623
2022-01-07T15:08:52
2022-01-07T15:08:52
27,980,012
0
0
null
null
null
null
UTF-8
Racket
false
false
771
rkt
match-hash-member.rkt
#lang racket/base (provide match-hash-member) (require racket/match (for-syntax racket/base syntax/parse )) (module+ test (require rackunit)) (define-match-expander match-hash-member (syntax-parser [(match-hash-member hsh-expr:expr key-pat:expr val-pat:expr) #'(app (let ([hsh hsh-expr]) (λ (k) (let/ec fail (list k (hash-ref hsh k (λ () (fail #f))))))) (list key-pat val-pat))])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (module+ test (check-equal? (match 'k [(match-hash-member (hash 'k 'v) k v) (list k v)]) '(k v)) )
false
63a13d89756189f27b4ef08117c7ca9320427137
d0ea449400a715f50fd720c265d2b923c34bc464
/digitama/stdin.rkt
d1ad3a53abb73587ccd7da62f26f5f00c6a6b188
[]
no_license
wargrey/psd
c3d69b8c7d6577cdac9be433be832e80d2bb32d4
73b16a52e0777250d02e977f7dcbd7c1d98ef772
refs/heads/master
2020-12-02T06:26:02.875227
2018-07-16T11:00:58
2018-07-16T11:00:58
96,830,933
1
1
null
null
null
null
UTF-8
Racket
false
false
4,318
rkt
stdin.rkt
#lang typed/racket/base (provide (all-defined-out)) (require racket/port) (require "draw.rkt") (require "image.rkt") (define select-psd-file : (-> Path-String Positive-Real Boolean (Values Path-String Positive-Real)) (lambda [src.psd density try?] (cond [(not try?) (values src.psd density)] [else (let* ([path.psd : String (if (string? src.psd) src.psd (path->string src.psd))] [[email protected] : String (regexp-replace #rx"([.][^.]*|)$" path.psd "@2x\\1")]) (cond [(not (file-exists? [email protected])) (values path.psd density)] [else (values [email protected] (+ density density))]))]))) (define read-psd-header : (-> Input-Port (Values Positive-Byte Positive-Byte Positive-Index Positive-Index Positive-Byte PSD-Color-Mode)) (lambda [/dev/psdin] (define signature : Bytes (read-nbytes* /dev/psdin 4)) (define version : Integer (read-integer /dev/psdin 2)) (unless (and (equal? signature #"8BPS") (or (= version 1) (= version 2))) (raise-user-error 'read-psd-header "this is not a valid PSD/PSB file: ~a" (object-name /dev/psdin))) (read-nbytes* /dev/psdin 6) ; reserved (values (if (fx= version 1) 4 8) (read-integer /dev/psdin 2 positive-byte?) ; channels (read-integer /dev/psdin 4 positive-index?) ; height (read-integer /dev/psdin 4 positive-index?) ; width (read-integer /dev/psdin 2 positive-byte?) ; depth (integer->color-mode (read-integer /dev/psdin 2))))) (define read-psd-subsection : (-> Input-Port Positive-Byte (Values Bytes Bytes (Option Bytes) (Option Bytes) (Option Bytes))) (lambda [/dev/psdin psd/psb-size] (define color-mode-data : Bytes (read-n:bytes /dev/psdin 4)) (define images-resources : Bytes (read-n:bytes /dev/psdin 4)) (define layer+mask-size : Index (read-integer /dev/psdin psd/psb-size index?)) (if (fx= layer+mask-size 0) (values color-mode-data images-resources #false #false #false) (let ([layer-info : Bytes (read-n:bytes /dev/psdin psd/psb-size)] [global-mask-info : Bytes (read-n:bytes /dev/psdin 4)]) (define layer-size : Index (bytes-length layer-info)) (define mask-size : Index (bytes-length global-mask-info)) (define tagged-blocks-size : Fixnum (fx- layer+mask-size (fx+ (fx+ psd/psb-size layer-size) (fx+ 4 mask-size)))) (values color-mode-data images-resources (and (fx> layer-size 0) layer-info) (and (fx> mask-size 0) global-mask-info) (and (fx> tagged-blocks-size 0) (read-nbytes* /dev/psdin tagged-blocks-size))))))) (define read-psd-composite-image : (-> Input-Port (Values PSD-Compression-Method Bytes)) (lambda [/dev/psdin] (values (integer->compression-method (read-integer /dev/psdin 2)) (port->bytes /dev/psdin)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define read-n:bytes : (-> Input-Port Fixnum Bytes) (lambda [/dev/psdin size] (read-nbytes* /dev/psdin (read-integer /dev/psdin size)))) (define read-integer : (All (a) (case-> [Input-Port Fixnum -> Integer] [Input-Port Fixnum (-> Any Boolean : a) -> a])) (case-lambda [(/dev/psdin bsize) (integer-bytes->integer (read-bytes* /dev/psdin bsize) #false #true 0 bsize)] [(/dev/psdin bsize subinteger?) (assert (read-integer /dev/psdin bsize) subinteger?)])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define read-bytes* : (-> Input-Port Integer Bytes) (lambda [/dev/psdin size] (define bs : (U Bytes EOF) (read-bytes size /dev/psdin)) (if (bytes? bs) bs (throw-eof-error /dev/psdin)))) (define read-nbytes* : (-> Input-Port Integer Bytes) (lambda [/dev/psdin size] (define bs : (U Bytes EOF) (read-bytes size /dev/psdin)) (cond [(and (bytes? bs) (= (bytes-length bs) size)) bs] [else (throw-eof-error /dev/psdin)]))) (define throw-eof-error : (-> Input-Port Nothing) (lambda [/dev/psdin] (raise (make-exn:fail:read:eof "unexpected end of file!" (continuation-marks #false) null))))
false
aa2682746d25de1bfb88b37060f5eac460a45ee2
01ed4efac0c29caeb9388c0c5c1e069da7c1eebf
/examples/market-notify/market-server-register.rkt
f31a6baf26f8348f738c2819ce8fffa81e4fadd1
[ "Apache-2.0" ]
permissive
karinies/coast
2124d69d467130b7efb03351fbcc974f9a9f4646
b520003d9c4ebb2775db2f07688e58bbd3199195
refs/heads/master
2020-04-01T23:02:24.547845
2017-05-26T21:43:27
2017-05-26T21:43:27
33,692,208
8
0
null
null
null
null
UTF-8
Racket
false
false
1,986
rkt
market-server-register.rkt
#lang racket/base (require "../../spawn.rkt" "../../getters.rkt" ) (provide market/subscribe market/subs/count market/subs/apply-all market/subs/apply market-event market-event/symbol market-event/type market-event/price market-event/quantity market-event/seller market-event/buyer ) (struct market-event (symbol ; Stock symbol. type ; The event type. price ; The share price in cents. quantity ; The amount of shares that are traded. seller ; The seller ID. buyer) ; The buyer ID. #:transparent) (struct/getters/define market-event symbol type price quantity seller buyer) (define market/registrations (make-hash)) ; The "Database" for market event registrations (define (market/subscribe symbols curl) (for-each (lambda (symbol) (cond [(hash-has-key? market/registrations symbol) ; is there already a key for this symbol? ; get the curl list, append new curl, update hash (hash-set! market/registrations symbol (append(hash-ref market/registrations symbol)(list curl)))] [else (hash-set! market/registrations symbol (list curl))])) ; otherwise, make a new list with single curl symbols)) (define (market/subs/count) ; Returns the number of entries in the DB. (hash-count market/registrations)) (define (market/subs/apply-all proc) ; apply proc to all subs passing key and value (hash-for-each market/registrations proc)) (define (market/subs/apply event proc) ; apply proc to only subs on symbol (cond [(hash-has-key? market/registrations (market-event-symbol event)) ; loop through curl list on hash calling (proc event curl) for each (for-each (lambda (curl) (proc event curl)) (hash-ref market/registrations (market-event-symbol event)))] [else (displayln (format "Unregistered symbol ~a" (market-event-symbol event)))]))
false
84579861b14cd0c6139c3880be73c96326488768
612da163dde8ad5c4ff647a2d37ebacd043dba76
/tests/sanitize-ids.rkt
c10c0be3ddf212db939e7e66946fa96e55a44c0a
[]
no_license
danking/tea-script
c777d90b1e25a8ff50716e9f8f4213e958fa5365
6c87c4572850d690de9f4411e98f442dbb199da8
refs/heads/master
2021-01-01T19:06:51.147052
2011-04-25T02:34:47
2011-04-25T02:34:47
1,093,973
2
0
null
null
null
null
UTF-8
Racket
false
false
3,579
rkt
sanitize-ids.rkt
#lang racket (require "../parser.rkt" rackunit "../sanitize-ids.rkt") (provide sanitize-ids-ts) (define p parse-tea-defexp) (define (sp sexp) (sanitize-ids (p sexp))) (define sanitize-ids-ts (test-suite "tests for sanitize-ids" (test-case "define statements" (check-equal? (sp '(define x 3)) (p '(define x 3))) (check-equal? (sp '(define foo-bar_ 3)) (p '(define foo_bar_0 3))) (check-equal? (sp '(define (foo-bar_ x) (if (empty? x) 'foo-bar_ (foo-bar_ (rest x))))) (p '(define (foo_bar_0 x) (if (emptyp0 x) 'foo-bar_ (foo_bar_0 (rest x))))))) (test-case "self-evals" (check-equal? (sp ''x) (p ''x)) (check-equal? (sp 3) (p 3)) (check-equal? (sp "foo") (p "foo"))) (test-case "list literals" (check-equal? (sp ''(1 2 3)) (p ''(1 2 3)))) (test-case "lambda" (check-equal? (sp '(lambda (x) x)) (p '(lambda (x) x))) (check-equal? (sp '(lambda (foo-bar) foo-bar)) (p '(lambda (foo_bar0) foo_bar0))) (check-equal? (sp '(lambda (foo-bar foo_bar) (+ foo-bar foo-bar))) (p '(lambda (foo_bar0 foo_bar) (a0 foo_bar0 foo_bar0))))) (test-case "let" (check-equal? (sp '(let ([foo-bar 3]) foo-bar)) (p '(let ([foo_bar0 3]) foo_bar0))) (check-equal? (sp '(let ([foo_bar 4] [foo~bar 2]) (+ (* 10 foo_bar) foo~bar))) (p '(let ([foo_bar 4] [foo_bar0 2]) (a0 (m0 10 foo_bar) foo_bar0))))) (test-case "send" (check-equal? (sp '(send foo bar)) (p '(send foo bar))) (check-equal? (sp '(send foo-bar_ foo_bar- 3 4)) (p '(send foo_bar_0 foo_bar- 3 4))) (check-equal? (sp '(send foo-bar_ foo-bar_ 3 4)) (p '(send foo_bar_0 foo-bar_ 3 4)))) (test-case "get-field" (check-equal? (sp '(get-field object field)) (p '(get-field object field))) (check-equal? (sp '(get-field object foo-bar_)) (p '(get-field object foo-bar_)))) (test-case "nested lets and lambdas" ;; this occasionally fails because order is lost in the set of symbols, ;; but this behavior does not cause identifier collisions ;; verify that the identifier bindings and references are preserved (check-equal? (sp '(let ([foo-bar 3]) (let ([foo_bar 5]) ((lambda (x foo~bar) (foo.bar foo_bar foo-bar foo~bar x)))))) (p '(let ([foo_bar0 3]) (let ([foo_bar 5]) ((lambda (x foo_bar2) (foo_bar1 foo_bar foo_bar0 foo_bar2 x)))))))) (test-case "stary-eyed fantasy -- SUCCESS!" (check-equal? (sp '(let ([foo-bar 3]) (let ([foo_bar 5]) (let ([foo~bar 7]) (procedure foo-bar foo_bar foo~bar))))) (p '(let ([foo_bar0 3]) (let ([foo_bar 5]) (let ([foo_bar1 7]) (procedure foo_bar0 foo_bar foo_bar1)))))))))
false
1705b6cecee08060c5a2b21ced8dad61c116ec36
2bb711eecf3d1844eb209c39e71dea21c9c13f5c
/test/unbound/lra/positive-sum1.rkt
6f75dabd061a7a9057d06c38a5734add571b0cf8
[ "BSD-2-Clause" ]
permissive
dvvrd/rosette
861b0c4d1430a02ffe26c6db63fd45c3be4f04ba
82468bf97d65bde9795d82599e89b516819a648a
refs/heads/master
2021-01-11T12:26:01.125551
2017-01-25T22:24:27
2017-01-25T22:24:37
76,679,540
2
0
null
2016-12-16T19:23:08
2016-12-16T19:23:07
null
UTF-8
Racket
false
false
708
rkt
positive-sum1.rkt
#lang rosette/unbound (require rackunit rackunit/text-ui rosette/lib/roseunit) (current-bitwidth #f) (define-symbolic n m integer?) ; m emulates a non-negative random value (define/unbound (positive-sum n) (~> integer? integer?) (cond [(= n 0) 0] [else (+ 1 m (positive-sum (- n 1)))])) (define positive-sum1-tests (test-suite+ "[unbound] Tests for lra/positive-sum1.rkt" (check-unsat (verify/unbound #:assume (assert (! (negative? m))) #:guarantee (assert (>= (positive-sum n) n)))) (check-sat (verify/unbound #:assume (assert (! (negative? m))) #:guarantee (assert (> (positive-sum n) n)))))) (time (run-tests positive-sum1-tests))
false
b540dbe2b404bb39e36ac9fc68a400494655dd07
9db1a54c264a331b41e352365e143c7b2b2e6a3e
/code/chapter_4/amb-interpreter.rkt
9b4e4eebedb15f36dfc07e33c8729bd75e4779c6
[]
no_license
magic3007/sicp
7103090baa9a52a372be360075fb86800fcadc70
b45e691ae056410d0eab57d65c260b6e489a145b
refs/heads/master
2021-01-27T10:20:28.743896
2020-06-05T15:17:10
2020-06-05T15:17:10
243,478,192
4
0
null
null
null
null
UTF-8
Racket
false
false
9,373
rkt
amb-interpreter.rkt
#lang racket ; http://lisp.test.openjudge.org/2020hw12/001/ (require scheme/mpair) ;================================================== (define (make-frame syms vals) (mmap mcons (list->mlist syms) (list->mlist vals))) (define (frame-look-up frame sym) (let ([rv (massoc sym frame)]) (if rv (values (mcdr rv) #t) (values (void) #f)))) (define (frame-set! frame sym val) (let ([rv (massoc sym frame)]) (if rv (begin (set-mcdr! rv val) #t) #f))) ;================================================== (struct EnvType ([frame #:mutable] ex-env)) (define (env-look-up env sym) (if (null? env) (error "unbounded symbol: " sym) (let-values ([(rv found?) (frame-look-up (EnvType-frame env) sym)]) (if found? rv (env-look-up (EnvType-ex-env env) sym))))) (define (env-set! env sym val) (if (null? env) (error "unbounded symbol: " sym) (let ([rv (frame-set! (EnvType-frame env) sym val)]) (if rv rv (env-set! (EnvType-ex-env env) sym val))))) (define (env-define env sym val) (set-EnvType-frame! env (mcons (mcons sym val) (EnvType-frame env)))) ;=================================================== (define (syms->frame syms) (if (null? syms) '() (mmap (lambda (sym) (if (pair? sym) (mcons (first sym) (second sym)) (mcons sym (eval sym (make-base-namespace))))) (list->mlist syms)))) (define primitive-frame (syms->frame `(+ - * / > < = >= <= quotient remainder cons car cdr cadr list not length append sqrt displayln void read number? symbol? null? pair? eq? equal? (false #f) (true #t)))) (define primitive-env (EnvType primitive-frame '())) ;=================================================== ; return a dispatching function whose result is a list of all the results in |lst| (define (serialize lst) (define (foo lst) (if (null? lst) (lambda (env scd fail) (scd '() fail)) (lambda (env scd fail) ((first lst) env (lambda (rv fail2) ((foo (rest lst)) env (lambda (rs fail3) (scd (cons rv rs) fail3)) fail2)) fail)))) (foo lst)) ;=================================================== (struct ProcedureType (syms fbody env)) (define (run-fproc fproc args env scd fail) (let* ([fargs (map analyze args)] [fe (serialize fargs)]) (fproc env (lambda (proc fail2) (fe env (lambda (vals fail3) (match proc [(ProcedureType syms fbody proc-env) (fbody (EnvType (make-frame syms vals) proc-env) scd fail3)] [primitive-proc (scd (apply primitive-proc vals) fail3)])) fail2)) fail))) ;=================================================== (define (analyze-begin bodys) (let* ([fbodys (map analyze bodys)] [fe (serialize fbodys)]) (lambda (env scd fail) (fe env (lambda (rv fail2) (scd (last rv) fail2)) fail)))) (define (analyze-apply proc args) (let ([fproc (analyze proc)]) (lambda (env scd fail) (run-fproc fproc args env scd fail)))) (define (analyze-lambda syms bodys) (let ([fbody (analyze-begin bodys)]) (lambda (env scd fail) (scd (ProcedureType syms fbody env) fail)))) (define (analyze-amb exps) (let ([fexps (map analyze exps)]) (lambda (env scd fail) (define (try-next choices) (if (null? choices) (fail) ((first choices) env scd (lambda () (try-next (rest choices)))))) (try-next fexps)))) (define (analyze-set! sym exp) (let ([fexp (analyze exp)]) (lambda (env scd fail) (fexp env (lambda (val fail2) (let* ([old-value (env-look-up env sym)]) (env-set! env sym val) (scd (void) (lambda () (env-set! env sym old-value) (fail2))))) fail)))) (define (analyze-define sym fexp) (lambda (env scd fail) (fexp env (lambda (rv fail2) (env-define env sym rv) (scd (void) fail2)) fail))) (define (analyze-if . args) (match (map analyze args) [`(,fpred ,fconseq ,falter) (lambda (env scd fail) (fpred env (lambda (rv fail2) (if rv (fconseq env scd fail2) (falter env scd fail2))) fail))] [_ (error "analyze-if error")])) (define (analyze-let pairs bodys) (let* ([syms (map first pairs)] [args (map second pairs)] [fproc (analyze-lambda syms bodys)]) (lambda (env scd fail) (run-fproc fproc args env scd fail)))) (define (analyze-cond pairs) (define (foo pa) (match pa [`(else . ,bodys) `(else ,(analyze-begin bodys))] [`(,pred . ,bodys) #:when (not (null? bodys)) `(,(analyze pred) ,(analyze-begin bodys))] [`(,pred) (analyze pred)] [_ (error "Error: analyze-cond")])) (let ([fpairs (map foo pairs)]) (define (scan e) (lambda (env scd fail) (if (null? e) (scd (void) fail) (match (first e) [`(else ,fbody) (fbody env scd fail)] [`(,fpred ,fbody) (fpred env (lambda (rv fail2) (if rv (fbody env scd fail2) ((scan (rest e)) env scd fail2))) fail)] [fpred (fpred env (lambda (rv fail2) (if rv (scd rv fail2) ((scan (rest e)) env scd fail2))) fail)])))) (scan fpairs))) (define (analyze-and exps) (let ([fexps (map analyze exps)]) (define (foo lst) (if (null? (rest lst)) (first lst) (lambda (env scd fail) ((first lst) env (lambda (rv fail2) (if (not rv) rv ((foo (rest lst)) env scd fail))) fail)))) (foo fexps))) (define (analyze-or exps) (let ([fexps (map analyze exps)]) (define (foo lst) (if (null? (rest lst)) (first lst) (lambda (env scd fail) ((first lst) env (lambda (rv fail2) (if rv rv ((foo (rest lst)) env scd fail))) fail)))) (foo fexps))) (define (self-evaluating? e) (or (number? e) (string? e) (boolean? e))) (define (analyze e) (match e [e #:when (self-evaluating? e) (lambda (env scd fail) (scd e fail))] [`',x (lambda (env scd fail) (scd x fail))] [`(begin . ,bodys) (analyze-begin bodys)] [`(apply ,proc . ,args) (analyze-apply proc args)] [`(lambda ,syms . ,bodys) (analyze-lambda syms bodys)] [`(set! ,sym ,exp) (analyze-set! sym exp)] [`(define (,proc . ,syms) . ,bodys) (analyze-define proc (analyze-lambda syms bodys))] [`(define ,sym ,exp) (analyze-define sym (analyze exp))] [`(let ,pairs . ,bodys) (analyze-let pairs bodys)] [`(if ,pred ,conseq ,alter) (analyze-if pred conseq alter)] [`(cond . ,pairs) (analyze-cond pairs)] [`(and . ,exps) (analyze-and exps)] [`(or . ,exps) (analyze-or exps)] [`(amb . ,exps) (analyze-amb exps)] [`(,proc . ,args) (analyze-apply proc args)] [x (lambda (env scd fail) (scd (env-look-up env x) fail))])) (define (amb-eval e) ((analyze e) primitive-env (lambda (x fail) x) (lambda () "no answer"))) (amb-eval `(define (require p) (if (not p) (amb) (void)))) ; ====================================================================== (define (check e ans) (let ([result (amb-eval e)]) (if (equal? result ans) (void) (begin (display ans) (display " expected, but ") (display result) (displayln " found") (error "assertion failed"))))) (check '(define (x) 1 2) (void)) (check '(x) 2) (check '(define x 2) (void)) (check 'x 2) (check '(set! x 3) (void)) (check 'x 3) (check '(cond [true 123 321] [else 'what 'ok]) 321) (check '(cond [false 222] [else 'what 'ok]) 'ok) (check '(begin (+ 1 2) 'hello) 'hello) (check '((lambda (x y) x) 1 2) 1) (check '(and (> 5 3) (> 6 2) (* 3 4)) 12) (check '(if true 233 345) 233) (check '(if true false 345) #f) (check '(let ([x 1] [y 2]) x y) 2) (check 'true #t) (check '(and #f #t) #f) (check '(or #f 555) 555) (check '(define (rand-update x) (define a 97) (define b 103) (define m 127) (remainder (+ (* a x ) b) m)) (void)) (check '(define rand (let ((t 6)) (lambda () (set! t (rand-update t)) t))) (void)) (check '(rand-update 6) 50) (check '(define haha (let ((t 6)) t)) (void)) (check 'haha 6) (check '(list (rand) (rand) (rand) (rand)) '(50 0 103 61)) ; ====================================================================== (define (driver) (let ([a (read)]) (when (not (eq? a eof)) (let ([rv (amb-eval a)]) (when (not (eq? rv (void))) (displayln rv)) (driver))))) (driver)
false
b12d6b40687f4ccba538a169bc299baac28ba709
4858557025c3294a2291ba4f4fef8ac3ceff2886
/Emulator/test/race-test.rkt
b3950a71cc9abc45c990f1bdba41746265554106
[]
no_license
prg-titech/Kani-CUDA
75e5b5bacd3edae5ee7f618e6d0760f57a54d288
e97c4bede43a5fc4031a7d2cfc32d71b01ac26c4
refs/heads/master
2021-01-20T00:21:21.151980
2019-03-26T02:42:02
2019-03-26T02:42:02
70,029,514
10
1
null
null
null
null
UTF-8
Racket
false
false
509
rkt
race-test.rkt
#lang rosette (require "../lang.rkt") (define arr (make-array (for/vector ([i (in-range 10)]) (make-element 0)) 10)) (define (test arr) (= [arr 0] 1) [arr 0]) (define (test-block-race arr) (: int x) (if (eq? (block-idx 0) 0) (begin (if- (eq?/LS (thread-idx 0) 0) (= [arr 0] 4)) ;(syncthreads) (if- (eq?/LS (thread-idx 0) 1) (= x [arr 0]))) (= x [arr 0]))) (invoke-kernel test-block-race '(2) '(5) arr) (print-matrix arr 10 1)
false
24c1e4b61dcd618ab7fd05aa3bcc73f01d5b42d2
c69acbecbe2d9f821e4a948564a29aba041415bc
/CheerLights/Twitter.rkt
9e5c3e41b89bc4dfa87504031d60eaf60631b0c7
[]
no_license
svdvonde/ActorReactor.Racket
349d0d3b8835d5b0ec2b4749601532e7e8fd0fdd
e9100b8bfe9dc46218e36c617175ce4f1e2e4336
refs/heads/master
2021-01-19T14:50:50.211210
2017-08-21T09:04:51
2017-08-21T09:04:51
100,931,194
0
0
null
null
null
null
UTF-8
Racket
false
false
990
rkt
Twitter.rkt
#lang racket (require "libs/oauth-single-user.rkt" "libs/lang/main.rkt" json) (provide TwitterBehaviour) (define TwitterBehaviour (ACTOR (LOCAL_STATE current-stream) (MESSAGE (open-stream keyword) (set! current-stream (send twitter-oauth get-request "https://stream.twitter.com/1.1/statuses/filter.json" (list (cons 'track keyword)))) (~> self read-tweet)) (MESSAGE (read-tweet) (define data (read-json current-stream)) (when (jsexpr? data) (define tweet-text (string-downcase (hash-ref data 'text))) (define tweet-chars (string-split tweet-text "")) (for-each (lambda (char) (SPIT 'tweet-char char)) tweet-chars) (~> self read-tweet)))))
false
1a34475eb3aa00d47f93a931b1c96c26aeb1ce42
45d66c1749fe706a5ee2656722884b88fb3d63c7
/racketimpl/uf-straightline.rkt
cb1b21da0d5f42efcefee09f853071919be8315c
[]
no_license
jn80842/frpsurvey
a7d5380f0c4fb7244bc659b7462ee4283f22c65d
2f3d61b1a8f7b164054690e680abe849fac5ce80
refs/heads/master
2021-01-11T19:47:20.039078
2019-01-25T07:18:11
2019-01-25T07:18:11
79,395,821
0
1
null
null
null
null
UTF-8
Racket
false
false
16,985
rkt
uf-straightline.rkt
#lang rosette (require "dense-fjmodels.rkt") (require "densefjapi.rkt") (provide (all-defined-out)) (struct stream-insn (op-index arg-index1 arg-index2 arg-index3 arg-int f) #:transparent) (struct operator (name call print) #:transparent) (define constantE-imm-op (operator "constantE" (λ (insn past-vars) (constantE (get-integer-arg insn) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (stream-insn-arg-int insn) (get-input-stream insn past-vars))))) (define constantE-op (operator "constantE" (λ (insn past-vars) (constantE (list-ref constantB-consts (stream-insn-arg-int insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (list-ref constantB-consts (stream-insn-arg-int insn)) (get-input-stream insn past-vars))))) (define mergeE-op (operator "mergeE" (λ (insn past-vars) (mergeE (list-ref past-vars (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (list-ref past-vars (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))))) (define collectE-imm-op (operator "collectE" (λ (insn past-vars) (collectE (get-integer-arg insn) (stream-insn-f insn) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a f ~a" (get-integer-arg insn) ; (list-ref function-2arg-list-string (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))))) (define collectE-op (operator "collectE" (λ (insn past-vars) (collectE (list-ref constantB-consts (stream-insn-arg-index2 insn)) (list-ref function-2arg-list (stream-insn-arg-index3 insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a ~a" (list-ref constantB-consts (stream-insn-arg-index2 insn)) (list-ref function-2arg-list-string (stream-insn-arg-int insn)) (get-input-stream insn past-vars))))) (define startsWith-imm-op (operator "startsWith" (λ (insn past-vars) (startsWith (get-integer-arg insn) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (stream-insn-arg-int insn) (get-input-stream insn past-vars))))) (define startsWith-op (operator "startsWith" (λ (insn past-vars) (startsWith (list-ref constantB-consts (stream-insn-arg-int insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (list-ref constantB-consts (stream-insn-arg-int insn)) (get-input-stream insn past-vars))))) (define mapE-op (operator "mapE" (λ (insn past-vars) (mapE (stream-insn-f insn) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "f ~a" ;(list-ref function-list-string (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))))) (define liftB1-op (operator "liftB1" (λ (insn past-vars) (liftB1 (list-ref function-list (stream-insn-arg-index2 insn)) (list-ref past-vars (stream-insn-arg-index1 insn)))) (λ (insn past-vars) (format "~a ~a" (list-ref function-list-string (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))))) (define liftB2-op (operator "liftB2" (λ (insn past-vars) (liftB2 (list-ref function-2arg-list (stream-insn-arg-index2 insn)) (list-ref past-vars (stream-insn-arg-index3 insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a ~a" (list-ref function-2arg-list-string (stream-insn-arg-index2 insn)) (list-ref past-vars (stream-insn-arg-index3 insn)) (list-ref past-vars (stream-insn-arg-index1 insn)))))) (define andB-op (operator "andB" (λ (insn past-vars) (andB (list-ref past-vars (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (list-ref past-vars (stream-insn-arg-index2 insn)) (list-ref past-vars (stream-insn-arg-index1 insn)))))) (define ifB-op (operator "ifB" (λ (insn past-vars) (ifB (get-input-stream insn past-vars) (list-ref past-vars (stream-insn-arg-index2 insn)) (list-ref past-vars (stream-insn-arg-index3 insn)))) (λ (insn past-vars) (format "~a ~a ~a" (get-input-stream insn past-vars) (list-ref past-vars (stream-insn-arg-index2 insn)) (list-ref past-vars (stream-insn-arg-index3 insn)))))) (define constantB-imm-op (operator "constantB" (λ (insn past-vars) (constantB (stream-insn-arg-int insn) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a" (stream-insn-arg-int insn))))) (define constantB-op (operator "constantB" (λ (insn past-vars) (constantB (list-ref constantB-consts (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a" (list-ref constantB-consts (stream-insn-arg-index2 insn)))))) (define collectB-op (operator "collectB" (λ (insn past-vars) (collectB (list-ref constantB-consts (stream-insn-arg-index2 insn)) (list-ref function-2arg-list (stream-insn-arg-index3 insn)) (list-ref past-vars (stream-insn-arg-index1 insn)))) (λ (insn past-vars) (format "~a ~a ~a" (list-ref constantB-consts (stream-insn-arg-index2 insn)) (list-ref function-2arg-list-string (stream-insn-arg-index3 insn)) (get-input-stream insn past-vars))))) (define collectB-imm-op (operator "collectB" (λ (insn past-vars) (collectB (get-integer-arg insn) (list-ref function-2arg-list (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a ~a" (get-integer-arg insn) (list-ref function-2arg-list-string (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars))))) (define snapshotE-op (operator "snapshotE" (λ (insn past-vars) (snapshotE (get-input-stream insn past-vars) (list-ref past-vars (stream-insn-arg-index2 insn)))) (λ (insn past-vars) (format "~a ~a" (get-input-stream insn past-vars) (list-ref past-vars (stream-insn-arg-index2 insn)))))) (define mapE2-op (operator "mapE" (λ (insn past-vars) (mapE2 (list-ref function-2arg-list (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars) (list-ref past-vars (stream-insn-arg-index3 insn)))) (λ (insn past-vars) (format "~a ~a ~a" (list-ref function-2arg-list-string (stream-insn-arg-index2 insn)) (get-input-stream insn past-vars) (list-ref past-vars (stream-insn-arg-index3 insn)))))) (define delayE-op (operator "delayE" (λ (insn past-vars) (delayE (get-integer-arg insn) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (get-integer-arg insn) (get-input-stream insn past-vars))))) (define filterRepeatsE-op (operator "filterRepeatsE" (λ (insn past-vars) (filterRepeatsE (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a" (get-input-stream insn past-vars))))) (define timerE-op (operator "timerE" (λ (insn past-vars) (timerE (get-integer-arg insn) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (get-integer-arg insn) (get-input-stream insn past-vars))))) (define filterE-op (operator "filterE" (λ (insn past-vars) (filterE (list-ref function-list (get-integer-arg insn)) (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a ~a" (list-ref function-list-string (get-integer-arg insn)) (get-input-stream insn past-vars))))) (define changes-op (operator "changes" (λ (insn past-vars) (changes (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a" (get-input-stream insn past-vars))))) (define notB-op (operator "notB" (λ (insn past-vars) (notB (get-input-stream insn past-vars))) (λ (insn past-vars) (format "~a" (get-input-stream insn past-vars))))) (define stateless-operator-list (list ;constantE-imm-op constantE-op mergeE-op mapE-op liftB1-op liftB2-op andB-op ifB-op constantB-imm-op constantB-op snapshotE-op mapE2-op filterE-op notB-op )) (define operator-list (list constantE-imm-op constantE-op mergeE-op mapE-op liftB1-op liftB2-op andB-op ifB-op constantB-imm-op constantB-op snapshotE-op mapE2-op filterE-op collectE-imm-op collectE-op startsWith-imm-op startsWith-op delayE-op filterRepeatsE-op timerE-op collectB-op collectB-imm-op changes-op )) ;; these are collectE specific var names ;; change back after experiments (define (get-insn-holes) (define-symbolic* op integer?) (define-symbolic* streamidx integer?) (define-symbolic* λidx integer?) (define-symbolic* arg3 integer?) (define-symbolic* arg-int integer?) (define-symbolic* f (~> integer? integer? integer?)) ;(define-symbolic* f (~> integer? integer?)) (stream-insn op streamidx λidx arg3 arg-int f)) (define (get-input-stream insn past-vars) (list-ref past-vars (stream-insn-arg-index1 insn))) (define (get-integer-arg insn) (stream-insn-arg-int insn)) (define (call-stateless-stream-insn insn past-vars) (let ([op (list-ref stateless-operator-list (stream-insn-op-index insn))]) ((operator-call op) insn past-vars))) (define (call-any-stream-insn insn past-vars) (let ([op (list-ref operator-list (stream-insn-op-index insn))]) ((operator-call op) insn past-vars))) (define (call-stream-insn state-flag insn past-vars) (if state-flag (call-any-stream-insn insn past-vars) (call-stateless-stream-insn insn past-vars))) (define (print-stream-insn state-flag insn varname past-vars) (let ([op (if state-flag (list-ref operator-list (stream-insn-op-index insn)) (list-ref stateless-operator-list (stream-insn-op-index insn)))]) (format " (define ~a (~a ~a))" varname (operator-name op) ((operator-print op) insn past-vars)))) ;; these lists are very unsatisfactory (define function-list (list (λ (e) (+ e 5)) (λ (t) (<= t 2)) (λ (c) (or (>= c 4) (>= 2 c))) (λ (e) (if e 'on 'off)) (λ (c) (or (>= (time-vec-hour c) 4) (>= 2 (time-vec-hour c)))) (λ (l) (= l 0)) (λ (m) (= m 3)) (λ (t) (and (eq? (vector-ref t 0) 18) (eq? (vector-ref t 1) 0) (eq? (vector-ref t 2) 0))) (λ (t) (and (eq? (vector-ref t 0) 18) (<= (vector-ref t 1) 2))) (λ (e) e) )) (define table (for/list ([i (range 3)]) (define-symbolic* table-sv integer?) table-sv)) (define function-2arg-list (list (λ (elt1 elt2) (+ elt1 elt2)) (λ (x y) (if x y x)) )) ;(define function-2arg-list (list + -)) ;(define function-2arg-list-string (list "+" "-")) (define function-list-string (list "(λ (e) (+ e 5))" "(λ (t) (<= t 2))" "(λ (c) (or (>= c 4) (>= 2 c)))" "(λ (e) (if e 'on 'off))" "(λ (c) (or (>= (time-vec-hour c) 4) (>= 2 (time-vec-hour c))))" "(λ (l) (= l 0)" "(λ (m) (= m 3)" "(λ (t) (and (eq? (vector-ref t 0) 18) (eq? (vector-ref t 1) 0) (eq? (vector-ref t 2) 0)))" "(λ (t) (and (eq? (vector-ref t 0) 18) (<= (vector-ref t 1) 2)))" "(λ (e) e)" )) (define function-2arg-list-string (list "(λ (elt1 elt2) (+ elt1 elt2))" "(λ (x y) (if x y x))" )) (define constantB-consts (list 'on 'off #t #f 'test)) (define (string-from-holes bound-holes state-mask retval input-count) (let* ([arg-list (for/list ([i (range input-count)]) (format "input~a" (add1 i)))] [input-stmt-list (for/list ([i (range input-count)]) (format " (define r~a input~a)" (add1 i) (add1 i)))] [depth (length bound-holes)] [varlist (for/list ([i (range (add1 (+ input-count depth)))]) (format "r~a" (add1 i)))] [synthed-stmt-list (for/list ([i (range depth)]) (print-stream-insn (vector-ref state-mask i) (list-ref bound-holes i) (list-ref varlist (+ input-count i)) (take varlist (+ input-count i))))] [return-stmt (format " ~a)" (list-ref varlist retval))]) (string-append (format "(define (synthesized-function ~a)\n" (string-join arg-list)) (string-join input-stmt-list "\n") "\n" (string-join synthed-stmt-list "\n") "\n" return-stmt))) ;; better parameterize the number of input streams (define (print-from-holes bound-holes state-mask retval input-count) (displayln (string-from-holes bound-holes state-mask retval input-count))) (define (recursive-sketch holes retval-idx state-mask) (letrec ([f (λ (calculated-streams i) (cond [(equal? (length holes) i) calculated-streams] [else (let ([next-stream (call-stream-insn (vector-ref state-mask i) (list-ref holes i) calculated-streams)]) (f (append calculated-streams (list next-stream)) (add1 i)))]))]) (λ inputs (list-ref (f inputs 0) retval-idx))))
false
80521528fa9f4d13b423ab041e5db5582c07830b
68fdf6c9da966d8e2ca18c58f7bdb9ce18ede028
/ease/main.rkt
d5a3ab3c4344fef5243f879ab192fe7a95b3ca93
[]
no_license
jackfirth/racket-ease
a442f12b7b4f312f6c7fa70c86cc7589ad0fcb84
3a7149ded68be348611e346742feac85fca6d74f
refs/heads/master
2021-01-01T05:35:48.830133
2015-08-27T20:40:40
2015-08-27T20:40:40
41,328,994
0
1
null
2015-12-30T00:01:38
2015-08-24T21:57:20
Racket
UTF-8
Racket
false
false
107
rkt
main.rkt
#lang sweet-exp racket/base require "private/main.rkt" provide all-from-out "private/main.rkt"
false
30273fc61c0e81cc83b715d27ec42eba561b1ffd
6858cbebface7beec57e60b19621120da5020a48
/14/3/2/1.rkt
d0b251c58455de2dcd3b484399aa1cb0b77d327d
[]
no_license
ponyatov/PLAI
a68b712d9ef85a283e35f9688068b392d3d51cb2
6bb25422c68c4c7717b6f0d3ceb026a520e7a0a2
refs/heads/master
2020-09-17T01:52:52.066085
2017-03-28T07:07:30
2017-03-28T07:07:30
66,084,244
2
0
null
null
null
null
UTF-8
Racket
false
false
125
rkt
1.rkt
<cps-macro-generator-case> ::= [(_ (generator (yield) (v) b)) (and (identifier? #'v) (identifier? #'yield)) <generator-body>]
false
c07ca724955eb79495fac7edd81d6b9d680aae8a
ec1873054ddc123742b656d0becf6e1e9d3f45fb
/defpat/docs/defpat.scrbl
e0542e3ae847c30d8b9db01f86b82c41b7fc3df7
[ "MIT" ]
permissive
AlexKnauth/defpat
ee07581911a78a277b436500b66f517cf4ba5e8d
40db819f1a3eaa230561c0b40b254a4de52f2b1e
refs/heads/master
2022-08-21T07:05:40.309755
2022-07-23T15:01:46
2022-07-23T15:01:46
21,782,941
0
0
null
null
null
null
UTF-8
Racket
false
false
3,755
scrbl
defpat.scrbl
#lang scribble/manual @(require scribble-code-examples (for-label racket/base racket/match defpat/defpat generic-bind)) @title{defpat} source code: @url{https://github.com/AlexKnauth/defpat} @defmodule[defpat/defpat]{ This module provides the forms @racket[defpat] and @racket[pat-lambda]. @racket[defpat] is a version of @racket[define] for functions where the arguments can be @racket[match] patterns. @margin-note{see also @racket[define/match] from @racketmodname[racket/match] and @racket[~define] from @racketmodname[generic-bind]} @racket[pat-lambda] is a version of @racket[lambda] where (again) the arguments can be @racket[match] patterns. @margin-note{see also @racket[match-lambda], @racket[match-lambda*], and @racket[match-lambda**] from @racketmodname[racket/match], and @racket[~lambda] from @racketmodname[generic-bind]} } @defform*[[(defpat id expr) (defpat (head args) body ...+)] #:grammar ([head id (head args)] [args (code:line arg ...) (code:line arg ... @#,racketparenfont{.} rest-id)] [arg (code:line arg-pat) (code:line [arg-pat default-expr]) (code:line keyword arg-pat) (code:line keyword [arg-pat default-expr])])]{ like @racket[define], except that each @racket[arg-pat] can be an arbitrary @racket[match] pattern. @code-examples[#:lang "racket/base" #:context #'here]{ (require defpat/defpat) (defpat (distance (list x1 y1) (list x2 y2)) (sqrt (+ (* (- x2 x1) (- x2 x1)) (* (- y2 y1) (- y2 y1))))) (distance (list 0 0) (list 3 4)) (distance (list 0 3) (list 4 0)) } The @racket[arg-pat] can't start with a @litchar{[} though, because square brackets are used to specify optional arguments: @code-examples[#:lang "racket/base" #:context #'here]{ (require defpat/defpat) ;; If the second point is not specified, it computes the ;; distance to the origin. (defpat (distance (list x1 y1) [(list x2 y2) (list 0 0)]) (sqrt (+ (* (- x2 x1) (- x2 x1)) (* (- y2 y1) (- y2 y1))))) (distance (list 0 3) (list 4 0)) (distance (list 3 4)) } @racketblock[(defpat (head . args) body ...)] expands to @racketblock[(defpat head (pat-lambda args body ...))] } @defform[(pat-lambda kw-formals body ...+) #:grammar ([kw-formals (arg ...) (arg ...+ . rest-id) rest-id] [arg (code:line arg-pat) (code:line [arg-pat default-expr]) (code:line keyword arg-pat) (code:line keyword [arg-pat default-expr])])]{ like @racket[lambda], except that each @racket[arg-pat] can be an arbitrary @racket[match] pattern. @margin-note*{Just as with @racket[defpat], the @racket[arg-pat] can't start with a @litchar{[}, and you have to use square brackets to specify an optional argument} It is very similar to @racket[match-lambda**], except that it doesn't support multiple clauses, and it allows optional arguments, keyword arguments, and a rest argument. As an example, @racketblock[(pat-lambda ((list x y) (vector z)) body)] expands to @racketblock[(lambda (%1 %2) (match-define (list x y) %1) (match-define (vector z) %2) body)] and for keyword-arguments, @racketblock[(pat-lambda (#:kw (list x y)) body)] expands to @racketblock[(lambda (#:kw %#:kw) (match-define (list x y) %#:kw) body)] }
false
bc6ee828f981d3497c468951e4c5c9a5674b777f
8d42c393da308254a67ecc500f50da5a436f53cc
/hive/common/info.rkt
d4424d1315a04e34849b92d08091aff70875400a
[ "MIT" ]
permissive
Kalimehtar/hive-common
1e25e0d15cf39c7e38d05c5ad7278a00c1bfecce
38d5bffacf8ddc6b8e0680997d23bf0502153bb7
refs/heads/master
2021-01-17T12:36:05.045690
2019-05-09T18:21:32
2019-05-09T18:21:32
56,967,266
0
1
null
2016-05-29T17:55:23
2016-04-24T11:06:49
Racket
UTF-8
Racket
false
false
70
rkt
info.rkt
#lang setup/infotab (define scribblings '(("hive-common.scrbl" ())))
false
fc6ea29535ed27c4cca3294f0b58ba46f4d241d2
98fd4b7b928b2e03f46de75c8f16ceb324d605f7
/drracket/scribblings/drracket/common.rkt
b52696ac62bf7192f1ebeda0d06d316be73e724e
[ "MIT", "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
racket/drracket
213cf54eb12a27739662b5e4d6edeeb0f9342140
2657eafdcfb5e4ccef19405492244f679b9234ef
refs/heads/master
2023-08-31T09:24:52.247155
2023-08-14T06:31:49
2023-08-14T06:32:14
27,413,460
518
120
NOASSERTION
2023-09-11T17:02:44
2014-12-02T03:36:22
Racket
UTF-8
Racket
false
false
371
rkt
common.rkt
#lang racket/base (require scribble/manual (for-label racket racket/gui/base)) (provide HtDP drlang (all-from-out scribble/manual) (for-label (all-from-out racket racket/gui/base))) (define HtDP (italic "How to Design Programs")) (define (drlang . s) (apply onscreen s))
false
d47825b4f8dbf06b2ee2bf767356aad12c56ad4e
5fa722a5991bfeacffb1d13458efe15082c1ee78
/src/c1_27.rkt
0a1c680def352605580da1cde63196c02e1725d3
[]
no_license
seckcoder/sicp
f1d9ccb032a4a12c7c51049d773c808c28851c28
ad804cfb828356256221180d15b59bcb2760900a
refs/heads/master
2023-07-10T06:29:59.310553
2013-10-14T08:06:01
2013-10-14T08:06:01
11,309,733
3
0
null
null
null
null
UTF-8
Racket
false
false
862
rkt
c1_27.rkt
#lang racket (require "prime.rkt") (require "base.rkt") (require racket/block) ;; a number is carmichael number if it fools the fermal test ;; ie it's not a prime number but it's congruent module to every number a < n (define (carmichael? n) (and (not (prime? n)) (congruent-every? n))) ;; check whether a^n % a = n for every a < n (define (congruent-every? n) (define (iter a) (cond ((>= a n) true) ((congruent-modulo? n a) (iter (+ a 1))) (else false))) (iter 2)) (define (test) (define (iter lst) (if (null? lst) (display "Done!\n") (block (display (car lst)) (newline) (display (carmichael? (car lst))) (newline) (display "***") (iter (cdr lst))))) (iter '(561 1105 1729 2465 2821 6601))) ;; the test shows that those numbers are carmichael number. (test)
false
2618d437115e11612c6fe59a033431421bf1ab67
630921f157f2a1d62ee20286c8ddc5d9e517509c
/elpa/racket-mode/cmds.rkt
e18d4a752fa29ce1f320adb820ae2dab4eb3b276
[ "MIT" ]
permissive
ahmadseleem/ViMacs
0027fad640951839b777c665424ee7cbe19fc38c
1967b49676c70a2de9937278b8fa9e2c737c6a00
refs/heads/master
2021-05-16T03:08:44.208609
2019-11-12T00:53:12
2019-11-12T00:53:12
20,172,841
7
0
null
null
null
null
UTF-8
Racket
false
false
17,851
rkt
cmds.rkt
#lang racket/base (require macro-debugger/analysis/check-requires racket/contract racket/file racket/format racket/function racket/list racket/match racket/port racket/pretty racket/set racket/string syntax/modresolve (only-in xml xexpr->string) "defn.rkt" "logger.rkt" "scribble.rkt" "try-catch.rkt" "util.rkt") (provide make-prompt-read) (module+ test (require rackunit)) (define (make-prompt-read path put/stop rerun) (define-values (base name dir?) (cond [path (split-path path)] [else (values "" "" #f)])) (λ () (let ([;; Elisp prints '() as 'nil. Reverse that. (Assumption: ;; Although Elisp code puns nil/() also to mean "false", ;; our Elisp code won't do that.) read (λ () (match (read) ['nil '()] [x x]))]) (flush-output (current-error-port)) (display #\u227a) (display name) (display #\u227b) (display #\space) (define in ((current-get-interaction-input-port))) (define stx ((current-read-interaction) (object-name in) in)) (syntax-case stx () [(uq cmd) (eq? 'unquote (syntax-e #'uq)) (case (syntax-e #'cmd) [(run) (run put/stop rerun)] [(top) (top put/stop rerun)] [(def) (def (read))] [(doc) (doc (read-syntax))] [(describe) (describe (read-syntax))] [(mod) (mod (read) path)] [(type) (type (read))] [(exp) (exp1 (read))] [(exp+) (exp+)] [(exp!) (exp! (read))] [(log) (log-display (map string->symbol (string-split (read-line))))] [(pwd) (display-commented (~v (current-directory)))] [(cd) (cd (~a (read)))] [(requires/tidy) (requires/tidy (read))] [(requires/trim) (requires/trim (read) (read))] [(requires/base) (requires/base (read) (read))] [else (usage)])] [_ stx])))) ;; Parameter-like interface, but we don't care about thread-local ;; stuff. We do care about calling collect-garbage IFF the new limit ;; is less than the old one or less than the current actual usage. (define current-mem (let ([old #f]) (case-lambda [() old] [(new) (and old new (or (< new old) (< (* new 1024 1024) (current-memory-use))) (collect-garbage)) (set! old new)]))) (define (run put/stop rerun) ;; Note: Use ~a on path to allow both `,run "/path/file.rkt"` and ;; `run /path/file.rkt`. (match (read-line->reads) [(list path mem) (cond [(number? mem) (current-mem mem) (put/stop (rerun (~a path) mem))] [else (usage)])] [(list path) (put/stop (rerun (~a path) (current-mem)))] [_ (usage)])) (define (top put/stop rerun) (match (read-line->reads) [(list mem) (cond [(number? mem) (current-mem mem) (put/stop (rerun #f mem))] [else (usage)])] [(list) (put/stop (rerun #f (current-mem)))] [_ (usage)])) (define (read-line->reads) (reads-from-string (read-line))) (define (reads-from-string s) (with-input-from-string s reads)) (define (reads) (match (read) [(? eof-object?) (list)] [x (cons x (reads))])) (define (usage) (displayln "Commands: ,run </path/to/file.rkt> [<memory-limit-MB>] ,top [<memory-limit-MB>] ,def <identifier> ,type <identifier> ,doc <identifier>|<string> ,exp <stx> ,exp+ ,exp! <stx> ,pwd ,cd <path> ,log <opts> ...") (void)) (define (def sym) (elisp-println (find-definition (symbol->string sym)))) (define (mod v rel) (define (mod* mod rel) (define path (with-handlers ([exn:fail? (λ _ #f)]) (resolve-module-path mod rel))) (and path (file-exists? path) (list (path->string path) 1 0))) (elisp-println (cond [(module-path? v) (mod* v rel)] [(symbol? v) (mod* (symbol->string v) rel)] [else #f]))) (define (type v) ;; the ,type command. rename this?? (elisp-println (type-or-sig v))) (define (type-or-sig v) (or (type-or-contract v) (sig v) "")) (define (sig v) ;symbol? -> (or/c #f string?) (define x (find-signature (symbol->string v))) (cond [x (~a x)] [else #f])) (define (type-or-contract v) ;any/c -> (or/c #f string?) ;; 1. Try using Typed Racket's REPL simplified type. (try (match (with-output-to-string (λ () ((current-eval) (cons '#%top-interaction v)))) [(pregexp "^- : (.*) \\.\\.\\..*\n" (list _ t)) t] [(pregexp "^- : (.*)\n$" (list _ t)) t]) #:catch exn:fail? _ ;; 2. Try to find a contract. (try (parameterize ([error-display-handler (λ _ (void))]) ((current-eval) (cons '#%top-interaction `(if (has-contract? ,v) (~a (contract-name (value-contract ,v))) (error))))) #:catch exn:fail? _ #f))) (define (sig-and/or-type stx) (define dat (syntax->datum stx)) (define s (or (sig dat) (~a dat))) (define t (type-or-contract stx)) (xexpr->string `(div () (p () ,s) ,@(if t `((pre () ,t)) `()) (br ())))) ;;; describe ;; If a symbol has installed documentation, display it. ;; ;; Otherwise, walk the source to find the signature of its definition ;; (because the argument names have explanatory value), and also look ;; for Typed Racket type or a contract, if any. ;; Keep reusing one temporary file. (define describe-html-path (make-temporary-file "racket-mode-describe-~a")) (define (describe stx) (with-output-to-file describe-html-path #:mode 'text #:exists 'replace (λ () (display (describe* stx)))) (elisp-println (path->string describe-html-path)) (void)) ;(void) prevents Typed Racket type annotation line (define (describe* _stx) (define stx (namespace-syntax-introduce _stx)) (or (scribble-doc/html stx) (sig-and/or-type stx))) ;;; print elisp values (define (elisp-println v) (elisp-print v) (newline)) (define (elisp-print v) (print (->elisp v))) (define (->elisp v) (match v [(or #f (list)) 'nil] [#t 't] [(? list? xs) (map ->elisp xs)] [(cons x y) (cons (->elisp x) (->elisp y))] [v v])) (module+ test (check-equal? (with-output-to-string (λ () (elisp-print '(1 t nil 3)))) "'(1 t nil 3)")) ;;; misc (define (doc stx) (eval (namespace-syntax-introduce (datum->syntax #f `(begin (local-require racket/help) (help ,stx)))))) (define (cd s) (let ([old-wd (current-directory)]) (current-directory s) (unless (directory-exists? (current-directory)) (display-commented (format "~v doesn't exist." (current-directory))) (current-directory old-wd)) (display-commented (format "In ~v" (current-directory))))) ;;; syntax expansion (define last-stx #f) (define (exp1 stx) (set! last-stx (expand-once stx)) (pp-stx last-stx)) (define (exp+) (when last-stx (define this-stx (expand-once last-stx)) (cond [(equal? (syntax->datum last-stx) (syntax->datum this-stx)) (display-commented "Already fully expanded.") (set! last-stx #f)] [else (pp-stx this-stx) (set! last-stx this-stx)]))) (define (exp! stx) (set! last-stx #f) (pp-stx (expand stx))) (define (pp-stx stx) (newline) (pretty-print (syntax->datum stx) (current-output-port) 1)) ;;; requires ;; requires/tidy : (listof require-sexpr) -> require-sexpr (define (requires/tidy reqs) (let* ([reqs (combine-requires reqs)] [reqs (group-requires reqs)]) (require-pretty-format reqs))) ;; requires/trim : path-string? (listof require-sexpr) -> require-sexpr ;; ;; Note: Why pass in a list of the existing require forms -- why not ;; just use the "keep" list from show-requires? Because the keep list ;; only states the module name, not the original form. Therefore if ;; the original require has a subform like `(only-in mod f)` (or ;; rename-in, except-in, &c), we won't know how to preserve that ;; unless we're given it. That's why our strategy must be to look for ;; things to drop, as opposed to things to keep. (define (requires/trim path-str reqs) (let* ([reqs (combine-requires reqs)] [sr (show-requires* path-str)] [drops (filter-map (λ (x) (match x [(list 'drop mod lvl) (list mod lvl)] [_ #f])) sr)] [reqs (filter-map (λ (req) (cond [(member req drops) #f] [else req])) reqs)] [reqs (group-requires reqs)]) (require-pretty-format reqs))) ;; Use `bypass` to help convert from `#lang racket` to `#lang ;; racket/base` plus explicit requires. ;; ;; Note: Currently this is hardcoded to `#lang racket`, only. (define (requires/base path-str reqs) (let* ([reqs (combine-requires reqs)] [sr (show-requires* path-str)] [drops (filter-map (λ (x) (match x [(list 'drop mod lvl) (list mod lvl)] [_ #f])) sr)] [adds (append* (filter-map (λ (x) (match x [(list 'bypass 'racket 0 (list (list mod lvl _) ...)) (filter (λ (x) (match x [(list 'racket/base 0) #f] [_ #t])) (map list mod lvl))] [_ #f])) sr))] [reqs (filter-map (λ (req) (cond [(member req drops) #f] [else req])) reqs)] [reqs (append reqs adds)] [reqs (group-requires reqs)]) (require-pretty-format reqs))) ;; show-requires* : Like show-requires but accepts a path-string? that ;; need not already be a module path. (define (show-requires* path-str) (define-values (base name dir?) (split-path (string->path path-str))) (parameterize ([current-load-relative-directory base] [current-directory base]) (show-requires name))) (define (combine-requires reqs) (remove-duplicates (append* (for/list ([req reqs]) (match req [(list* 'require vs) (append* (for/list ([v vs]) ;; Use (list mod level), like `show-requires` uses. (match v [(list* 'for-meta level vs) (map (curryr list level) vs)] [(list* 'for-syntax vs) (map (curryr list 1) vs)] [(list* 'for-template vs) (map (curryr list -1) vs)] [(list* 'for-label vs) (map (curryr list #f) vs)] [v (list (list v 0))])))]))))) (module+ test (require rackunit) (check-equal? (combine-requires '((require a b c) (require d e) (require a f) (require (for-syntax s t u) (for-label l0 l1 l2)) (require (for-meta 1 m1a m1b) (for-meta 2 m2a m2b)))) '((a 0) (b 0) (c 0) (d 0) (e 0) (f 0) (s 1) (t 1) (u 1) (l0 #f) (l1 #f) (l2 #f) (m1a 1) (m1b 1) (m2a 2) (m2b 2)))) ;; Given a list of requires -- each in the (list module level) form ;; used by `show-requires` -- group them by level and convert them to ;; a Racket `require` form. Also, sort the subforms by phase level: ;; for-syntax, for-template, for-label, for-meta, and plain (0). ;; Within each such group, sort them first by module paths then ;; relative requires. Within each such group, sort alphabetically. ;; ;; Note: Does *not* attempt to sort things *within* require subforms ;; such as except-in, only-in and so on. Such forms are only sorted in ;; between module paths and relative requires. (define (group-requires reqs) ;; Put the requires into a hash of sets. (define ht (make-hasheq)) ;(hash/c <level> (set <mod>)) (for ([req reqs]) (match req [(list mod lvl) (hash-update! ht lvl (lambda (s) (set-add s mod)) (set mod))])) (define (mod-set->mod-list mod-set) (sort (set->list mod-set) mod<?)) (define (for-level level k) (define mods (hash-ref ht level #f)) (cond [mods (k (mod-set->mod-list mods))] [else '()])) (define (preface . pres) (λ (mods) `((,@pres ,@mods)))) (define (meta-levels) (sort (for/list ([x (hash-keys ht)] #:when (not (member x '(-1 0 1 #f)))) x) <)) `(require ,@(for-level 1 (preface 'for-syntax)) ,@(for-level -1 (preface 'for-template)) ,@(for-level #f (preface 'for-label)) ,@(append* (for/list ([level (in-list (meta-levels))]) (for-level level (preface 'for-meta level)))) ,@(for-level 0 values))) (module+ test (check-equal? (group-requires (combine-requires '((require z c b a) (require (for-meta 4 m41 m40)) (require (for-meta -4 m-41 m-40)) (require (for-label l1 l0)) (require (for-template t1 t0)) (require (for-syntax s1 s0)) (require "a.rkt" "b.rkt" "c.rkt" "z.rkt" (only-in "mod.rkt" oi) (only-in mod oi))))) '(require (for-syntax s0 s1) (for-template t0 t1) (for-label l0 l1) (for-meta -4 m-40 m-41) (for-meta 4 m40 m41) a b c (only-in mod oi) z "a.rkt" "b.rkt" "c.rkt" (only-in "mod.rkt" oi) "z.rkt"))) (define (mod<? a b) (define (key x) (match x [(list 'only-in m _ ...) (key m)] [(list 'except-in m _ ...) (key m)] [(list 'prefix-in _ m) (key m)] [(list 'relative-in _ m _ ...) (key m)] [m m])) (let ([a (key a)] [b (key b)]) (or (and (symbol? a) (not (symbol? b))) (and (list? a) (not (list? b))) (and (not (string? a)) (string? a)) (and (string? a) (string? b) (string<? a b)) (and (symbol? a) (symbol? b) (string<? (symbol->string a) (symbol->string b)))))) (module+ test (check-true (mod<? 'a 'b)) (check-false (mod<? 'b 'a)) (check-true (mod<? 'a '(only-in b))) (check-true (mod<? '(only-in a) 'b)) (check-true (mod<? 'a '(except-in b))) (check-true (mod<? '(except-in a) 'b)) (check-true (mod<? 'a '(prefix-in p 'b))) (check-true (mod<? '(prefix-in p 'a) 'b)) (check-true (mod<? 'a '(relative-in p 'b))) (check-true (mod<? '(relative-in p 'a) 'b)) (check-true (mod<? 'a '(prefix-in p (only-in b)))) (check-true (mod<? '(prefix-in p (only-in a)) 'b))) ;; require-pretty-format : list? -> string? (define (require-pretty-format x) (define out (open-output-string)) (parameterize ([current-output-port out]) (require-pretty-print x)) (get-output-string out)) (module+ test (check-equal? (require-pretty-format '(require a)) "(require a)\n") (check-equal? (require-pretty-format '(require a b)) "(require a\n b)\n") (check-equal? (require-pretty-format '(require (for-syntax a b) (for-meta 2 c d) e f)) "(require (for-syntax a\n b)\n (for-meta 2 c\n d)\n e\n f)\n")) ;; Pretty print a require form with one module per line and with ;; indentation for the `for-X` subforms. Example: ;; ;; (require (for-syntax racket/base ;; syntax/parse) ;; (for-meta 3 racket/a ;; racket/b) ;; racket/format ;; racket/string ;; "a.rkt" ;; "b.rkt") ;; ;; Note: Does *not* attempt to format things *within* require subforms ;; such as except-in, only-in and so on. Each such form is put on its ;; own line, but might run >80 chars. (define (require-pretty-print x) (define (prn x first? indent) (define (indent-string) (if first? "" (make-string indent #\space))) (define (prn-form pre this more) (define new-indent (+ indent (+ 2 (string-length pre)))) (printf "~a(~a " (indent-string) pre) (prn this #t new-indent) (for ([x more]) (newline) (prn x #f new-indent)) (display ")")) (match x [(list 'require) (void)] [(list* (and pre (or 'require 'for-syntax 'for-template 'for-label)) this more) (prn-form (format "~s" pre) this more) (when (eq? pre 'require) (newline))] [(list* 'for-meta level this more) (prn-form (format "for-meta ~a" level) this more)] [this (printf "~a~s" (indent-string) this)])) (prn x #t 0))
false
416be863b6a302f30864c1eca215309a35efa7cf
98fd12cbf428dda4c673987ff64ace5e558874c4
/sicp/v1/chapter-2.3/ynasser-2.3.4.rkt
a1cf823a9e8ebe2d5d7453e1c6c0c5d68fc767d2
[ "Unlicense" ]
permissive
CompSciCabal/SMRTYPRTY
397645d909ff1c3d1517b44a1bb0173195b0616e
a8e2c5049199635fecce7b7f70a2225cda6558d8
refs/heads/master
2021-12-30T04:50:30.599471
2021-12-27T23:50:16
2021-12-27T23:50:16
13,666,108
66
11
Unlicense
2019-05-13T03:45:42
2013-10-18T01:26:44
Racket
UTF-8
Racket
false
false
2,913
rkt
ynasser-2.3.4.rkt
#lang racket (define (make-leaf symbol weight) (list 'leaf symbol weight)) (define (leaf? object) (eq? (car object) 'leaf)) (define (symbol-leaf x) (cadr x)) ;; car cdr (define (weight-leaf x) (caddr x)) ;; car cdr cdr (define (make-code-tree left right) (list left right (append (symbols left) (symbols right)) (+ (weight left) (weight right)))) (define (left-branch tree) (car tree)) (define (right-branch tree) (cadr tree)) (define (symbols tree) (if (leaf? tree) (list (symbol-leaf tree)) (caddr tree))) (define (weight tree) (if (leaf? tree) (weight-leaf tree) (cadddr tree))) (define (decode bits tree) (define (decode-1 bits current-branch) (if (null? bits) '() (let ((next-branch (choose-branch (car bits) current-branch))) (if (leaf? next-branch) (cons (symbol-leaf next-branch) (decode-1 (cdr bits) tree)) (decode-1 (cdr bits) next-branch))))) (decode-1 bits tree)) (define (choose-branch bit branch) (cond ((= bit 0) (left-branch branch)) ((= bit 1) (right-branch branch)) (else (error "bad bit -- CHOOSE-BRANCH" bit)))) (define (adjoin-set x set) (cond ((null? set) (list x)) ((< (weight x) (weight (car set))) (cons x set)) (else (cons (car set) (adjoin-set x (cdr set)))))) (define (make-leaf-set pairs) (if (null? pairs) '() (let ((pair (car pairs))) (adjoin-set (make-leaf (car pair) ; symbol (cadr pair)) ; frequency (make-leaf-set (cdr pairs)))))) ;; Exercise 2.67 ;; Use the decode procedure to decode the message, and give the result! (define sample-tree (make-code-tree (make-leaf 'A 4) (make-code-tree (make-leaf 'B 2) (make-code-tree (make-leaf 'D 1) (make-leaf 'C 1))))) (define sample-message '(0 1 1 0 0 1 0 1 0 1 1 1 0)) ;; (decode sample-message sample-tree) => '(A D A B B C A) ;; Exercise 2.68 ;; Implement encode-symbol such that it returns an error if the symbol is not ;; in the tree. (define m (decode sample-message sample-tree)) ;; '(A D A B B C A) (define (encode-symbol-1 symbol tree) (cond [(leaf? tree) null] [(member symbol (symbols (left-branch tree))) (append '(0) (encode-symbol-1 symbol (left-branch tree)))] [else (append '(1) (encode-symbol-1 symbol (right-branch tree)))])) (define (encode-symbol s t) (cond [(not (member s (symbols t))) (error "bad bit!")] [else (encode-symbol-1 s t)])) (define (encode message tree) (if (null? message) '() (append (encode-symbol (car message) tree) (encode (cdr message) tree)))) ;; Exercise 2.69 (define (successive-merge) 'what)
false
94e9e1536efc8b0ead6a99d272b6fc32bd76caf8
35342a665303f172ce674a32bbc9ee1374c3fd7d
/src/scribble-extras.rkt
f841901b5edad5fdb8f2e1be37018373c40271a0
[ "MIT" ]
permissive
themattchan/toad
dda0d592ff2e9da2212258e287892f921e7bd682
843bc19598062886f8d0d680feaea4949bdc7e84
refs/heads/master
2021-01-21T13:08:39.191294
2016-05-26T12:04:27
2016-05-26T12:04:27
36,687,209
1
1
null
null
null
null
UTF-8
Racket
false
false
52
rkt
scribble-extras.rkt
#lang racket ; TODO: add a code struct to scribble
false
69b351b3361d8cd021cb4a9d9ccd353792166a85
2bb711eecf3d1844eb209c39e71dea21c9c13f5c
/test/unbound/mochi/sum_intro.rkt
0e6f70641703362b0a256219e29daa687577b350
[ "BSD-2-Clause" ]
permissive
dvvrd/rosette
861b0c4d1430a02ffe26c6db63fd45c3be4f04ba
82468bf97d65bde9795d82599e89b516819a648a
refs/heads/master
2021-01-11T12:26:01.125551
2017-01-25T22:24:27
2017-01-25T22:24:37
76,679,540
2
0
null
2016-12-16T19:23:08
2016-12-16T19:23:07
null
UTF-8
Racket
false
false
267
rkt
sum_intro.rkt
#lang rosette/unbound (dbg-level 0) (define-symbolic n integer?) (define (add x y) (+ x y)) (define/unbound (sum n) (~> integer? integer?) (cond [(<= n 0) 0] [else (+ n (sum (- n 1)))])) ; Expecting unsat (time (verify/unbound (assert (<= n (sum n)))))
false
ad534dc16115551965d5683ec874ae461bfff3ea
bb6ddf239800c00988a29263947f9dc2b03b0a22
/solutions/exercise-2.18.rkt
0076246db63a7ecd2b2fb9de1be237367ae974e2
[]
no_license
aboots/EOPL-Exercises
f81b5965f3b17f52557ffe97c0e0a9e40ec7b5b0
11667f1e84a1a3e300c2182630b56db3e3d9246a
refs/heads/master
2022-05-31T21:29:23.752438
2018-10-05T06:38:55
2018-10-05T06:38:55
null
0
0
null
null
null
null
UTF-8
Racket
false
false
3,092
rkt
exercise-2.18.rkt
#lang eopl ;; Exercise 2.18 [★] We usually represent a sequence of values as a list. In this representation, it is easy to move ;; from one element in a sequence to the next, but it is hard to move from one element to the preceding one without the ;; help of context arguments. Implement non-empty bidirectional sequences of integers, as suggested by the grammar ;; ;; NodeInSequence ::= (Int Listof(Int) Listof(Int)) ;; ;; The first list of numbers is the elements of the sequence preceding the current one, in reverse order, and the second ;; list is the elements of the sequence after the current one. For example, (6 (5 4 3 2 1) (7 8 9)) represents the list ;; (1 2 3 4 5 6 7 8 9), with the focus on the element 6. ;; ;; In this representation, implement the procedure number->sequence, which takes a number and produces a sequence ;; consisting of exactly that number. Also implement current-element, move-to-left, move-to-right, insert-to-left, ;; insert-to-right, at-left-end?, and at-right-end?. ;; ;; For example: ;; ;; > (number->sequence 7) ;; (7 () ()) ;; > (current-element '(6 (5 4 3 2 1) (7 8 9))) ;; 6 ;; > (move-to-left '(6 (5 4 3 2 1) (7 8 9))) ;; (5 (4 3 2 1) (6 7 8 9)) ;; > (move-to-right '(6 (5 4 3 2 1) (7 8 9))) ;; (7 (6 5 4 3 2 1) (8 9)) ;; > (insert-to-left 13 '(6 (5 4 3 2 1) (7 8 9))) ;; (6 (13 5 4 3 2 1) (7 8 9)) ;; > (insert-to-right 13 '(6 (5 4 3 2 1) (7 8 9))) ;; (6 (5 4 3 2 1) (13 7 8 9)) ;; ;; The procedure move-to-right should fail if its argument is at the right end of the sequence, and the procedure ;; move-to-left should fail if its argument is at the left end of the sequence. (define number->sequence (lambda (num) (list num '() '()))) (define current-element car) (define move-to-left (lambda (node) (let ([before (cadr node)]) (if (null? before) (eopl:error 'move-to-left "Cannot move to left when at left end.") (let ([num (car node)] [after (caddr node)]) (list (car before) (cdr before) (cons num after))))))) (define move-to-right (lambda (node) (let ([after (caddr node)]) (if (null? after) (eopl:error 'move-to-right "Cannot move to right when at right end.") (let ([num (car node)] [before (cadr node)]) (list (car after) (cons num before) (cdr after))))))) (define insert-to-left (lambda (num node) (let ([current (car node)] [before (cadr node)] [after (caddr node)]) (list current (cons num before) after)))) (define insert-to-right (lambda (num node) (let ([current (car node)] [before (cadr node)] [after (caddr node)]) (list current before (cons num after))))) (define at-left-end? (lambda (node) (null? (cadr node)))) (define at-right-end? (lambda (node) (null? (caddr node)))) (provide number->sequence current-element move-to-left move-to-right insert-to-left insert-to-right at-left-end? at-right-end?)
false
849a38703e8324e008f61a68bcf2adacfe9b7b32
de7b0198461a277cf1fcf6ccdd2fc2673be70c77
/utils.rkt
fac01b8b75b59785846f9885542974862cc39d18
[]
no_license
KasoLu/KSLang
99fdca1a8c5fa94b9212a7e9b9f86989b5ea2599
96d62fd6e0eb714ccecae531be583d32d7e59f6c
refs/heads/master
2020-05-19T12:25:24.089878
2019-05-21T07:26:56
2019-05-21T07:26:56
185,014,346
0
0
null
null
null
null
UTF-8
Racket
false
false
677
rkt
utils.rkt
#lang racket (provide (all-defined-out)) (require racket/trace) ;(define-syntax lambda ; (syntax-rules () ; [(_ kw body ...) (trace-lambda kw body ...)])) (define pipe (lambda funcs (lambda (v) (foldl (lambda (f v) (f v)) v funcs)))) (define chars->symbol (pipe list->string string->symbol)) (define chars->number (pipe list->string string->number)) (define read-file (lambda (filename) (let ([port (open-input-file filename #:mode 'text)]) (let loop ([line (read-line port)] [all ""]) (cond [(eof-object? line) all] [else (loop (read-line port) (string-append all line "\n"))])))))
true
eff3496c5e0682d34ab3b648407861e87a2c4fa2
67c87680aa55f10aeaaaa3d755573313ab4af46d
/2/31.rkt
8f863a1be395e77cc2ebb845a046364ae90260a0
[]
no_license
noahlt/sicp
5f6cdac4b291cbbd86f946dcc71fa654e2f5ef0a
b210886218c1f45de2a03df75c578d2889f460fc
refs/heads/master
2020-12-30T09:58:01.580566
2016-01-31T17:34:38
2016-01-31T17:34:38
8,126,410
1
0
null
null
null
null
UTF-8
Racket
false
false
371
rkt
31.rkt
#lang racket (define (tree-map f tree) (cond ((null? tree) (list)) ((not (pair? tree)) (f tree)) (else (cons (tree-map f (car tree)) (tree-map f (cdr tree)))))) (define (square x) (* x x)) (define (square-tree tree) (tree-map square tree)) (define test-tree (list 1 (list 2 (list 3 4) 5) (list 6 7))) (square-tree test-tree)
false
05f567ac5c5912148449d3fd289652da2295670d
fc90b5a3938850c61bdd83719a1d90270752c0bb
/web-server-lib/web-server/main.rkt
940effe8a75d8c25eaaed9a4da321d4108274cf7
[ "MIT", "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
racket/web-server
cccdf9b26d7b908701d7d05568dc6ed3ae9e705b
e321f8425e539d22412d4f7763532b3f3a65c95e
refs/heads/master
2023-08-21T18:55:50.892735
2023-07-11T02:53:24
2023-07-11T02:53:24
27,431,252
91
42
NOASSERTION
2023-09-02T15:19:40
2014-12-02T12:20:26
Racket
UTF-8
Racket
false
false
157
rkt
main.rkt
#lang racket/base (require "private/launch.rkt" (only-in "web-server.rkt" do-not-return)) (void (serve)) (do-not-return) (module test racket/base)
false
5b3c2695595e2bf31adc3f18ac825cd8fbc322e7
bdb6b8f31f1d35352b61428fa55fac39fb0e2b55
/sicp/ex2.60.rkt
dfe1f6a6deeb930cf688d805625be1a029d03b49
[]
no_license
jtskiba/lisp
9915d9e5bf74c3ab918eea4f84b64d7e4e3c430c
f16edb8bb03aea4ab0b4eaa1a740810618bd2327
refs/heads/main
2023-02-03T15:32:11.972681
2020-12-21T21:07:18
2020-12-21T21:07:18
323,048,289
0
0
null
null
null
null
UTF-8
Racket
false
false
1,386
rkt
ex2.60.rkt
#lang racket ;ex2.60 ; now working with possible duplicates within set (ok) (define (element-of-set? x set) (cond ((null? set) false) ((equal? x (car set)) true) (else (element-of-set? x (cdr set))))) (define (adjoin-set x set) (cons x set)) (define (intersection-set set1 set2) (cond ((or (null? set1) (null? set2)) '()) ((element-of-set? (car set1) set2) (cons (car set1) (intersection-set (cdr set1) (remove-from-set (car set1) set2)))) (else (intersection-set (cdr set1) set2)))) (define (remove-from-set x set) ; removes only one instance of x, not all from the set (cond ((null? set) '()) ((not (equal? x (car set))) (cons (car set) (remove-from-set x (cdr set)))) (else (cdr set)))) (define (union-set set1 set2) (append set1 set2)) (element-of-set? 2 '(2 3 2 1 3 2 2)) ;no change to element-of-set? (adjoin-set 2 '(2 3 2 1 3 2 2)) ; removed condition checking if x in set, we add it anyway even if duplicate (intersection-set '(2 2 3 3 3) '(2 3 2 1 3 2 2)) ;i want (2 2 3 3) - done - had to create remove-from-set where single instance of x is removed from set (remove-from-set 2 '(1 2 2 2 3)); example of how this new fn works (union-set '(2 2 3 3 3) '(2 3 2 1 3 2 2)) ; this will now be effectively an append fn
false
1e43d4ba188c948afaffa36cb6e64dc508b3a8a8
6a517ffeb246b6f87e4a2c88b67ceb727205e3b6
/lib/boolean.rkt
829b9348a82413d6def5dabc773945e217334625
[]
no_license
LiberalArtist/ecmascript
5fea8352f3152f64801d9433f7574518da2ae4ee
69fcfa42856ea799ff9d9d63a60eaf1b1783fe50
refs/heads/master
2020-07-01T01:12:31.808023
2019-02-13T00:42:35
2019-02-13T00:42:35
null
0
0
null
null
null
null
UTF-8
Racket
false
false
1,414
rkt
boolean.rkt
#lang racket/base (require racket/class racket/lazy-require "../private/object.rkt" "../private/primitive.rkt" "../private/this.rkt" (only-in "function.rkt" Function%) (only-in "object.rkt" Object:prototype) "util.rkt") (lazy-require ["../convert.rkt" (to-boolean)]) (provide get-properties make-Boolean) (define (get-properties) `(["Boolean" . ,boolean-constructor])) (define Boolean% (class ecma-object% (init-field value) (init [prototype Boolean:prototype]) (super-new [class-name 'Boolean] [prototype prototype]))) (define Boolean:prototype (new Boolean% [prototype Object:prototype] [value #f])) (define (make-Boolean value) (new Boolean% [value value])) (define boolean-constructor (new (class Function% (super-new [formal-parameters '(value)] [proc to-boolean]) (define/override (construct args) (let ([value (if (null? args) ecma:undefined (car args))]) (make-Boolean (to-boolean value))))))) (define-object-properties boolean-constructor ["prototype" Boolean:prototype]) (define-object-properties Boolean:prototype ["constructor" boolean-constructor] ["toString" (native-method () (if (get-field value ecma:this) "true" "false"))] ["valueOf" (native-method () (get-field value ecma:this))])
false
b9f44b3d93c9ed8afde600ae42d268b4096a1b5d
e553691752e4d43e92c0818e2043234e7a61c01b
/rosette/base/core/equality.rkt
dff56a3e3da96ad1171320b0639f2623b5c287c0
[ "BSD-2-Clause" ]
permissive
emina/rosette
2b8c1bcf0bf744ba01ac41049a00b21d1d5d929f
5dd348906d8bafacef6354c2e5e75a67be0bec66
refs/heads/master
2023-08-30T20:16:51.221490
2023-08-11T01:38:48
2023-08-11T01:38:48
22,478,354
656
89
NOASSERTION
2023-09-14T02:27:51
2014-07-31T17:29:18
Racket
UTF-8
Racket
false
false
2,783
rkt
equality.rkt
#lang racket (require "term.rkt" "union.rkt" "bool.rkt") (provide @eq? ; (-> any/c any/c @boolean?) @equal?) ; (-> any/c any/c @boolean?) ; We must use identity-based hashing and comparison of user-provided values, ; because user-defined structs can override equal/hash and cause unexpected ; errors when the overriden equal? is repeatedly called by a hash map. We also ; have to use (below) identity-based comparisons for shortcircuiting for the ; same reason---equal? might be overriden by a user-defined struct. (struct key (x y) #:transparent #:methods gen:equal+hash [(define (equal-proc a b equal?-recur) (and (eq? (key-x a) (key-x b)) (eq? (key-y a) (key-y b)))) (define (hash-proc a hash-recur) (hash-recur (cons (eq-hash-code (key-x a)) (eq-hash-code (key-y a))))) (define (hash2-proc a hash2-recur) (hash2-recur (cons (eq-hash-code (key-y a)) (eq-hash-code (key-x a)))))]) (define-syntax-rule (define-equality-predicate @=? type=? @cache @make-hash) (define (@=? x y) (let* ([cache (@cache)] [toplevel? (false? cache)] [k (key x y)]) (when toplevel? (set! cache (@make-hash)) (@cache cache)) (if (hash-has-key? cache k) (hash-ref cache k) (begin (hash-set! cache k #t) (let ([result (cond [(eq? x y) #t] ; We must use identity-based comparisons for short-circuiting. [(union? x) (if (union? y) (union=union? x y @=?) (union=value? x y @=?))] [(union? y) (union=value? y x @=?)] [else (type=? (type-of x y) x y)])]) (if toplevel? (@cache #f) (hash-set! cache k result)) result)))))) (define equal-cache (make-parameter #f)) (define eq-cache (make-parameter #f)) (define-equality-predicate @equal? type-equal? equal-cache make-hash) (define-equality-predicate @eq? type-eq? eq-cache make-hash) ; (-> union? union? (-> any/c any/c @boolean?) @boolean?) (define (union=union? x y =?) (match* (x y) [((union vs t) (union ws s)) (and (or (subtype? t s) (subtype? s t)) (apply || (for*/list ([v vs] [w ws]) (and-&& (=? (cdr v) (cdr w)) (car v) (car w)))))])) ; (-> union? (not/c union?) (-> any/c any/c @boolean?) @boolean?) (define (union=value? x y =?) (match* (x y) [((union vs t) (app type-of s)) (and (or (subtype? t s) (subtype? s t)) (apply || (for/list ([v vs]) (and-&& (=? y (cdr v)) (car v)))))]))
true
5c7cbfc5bc2adc7b410b9ed18916baf30a239947
fc1275d5dfc7e31b465ad5e0009793385db11dba
/termios/defines.rkt
404b917f858b734c934c0bff9fde6066cf7ccd81
[]
no_license
BartAdv/racket-termios
ecfcf55fa78f8ed48f6d0412f96aab803f8db39f
b6632c54c587577c0cce86e62a72e9b09c38342e
refs/heads/master
2020-06-01T01:02:18.932358
2015-03-30T13:32:29
2015-03-30T13:32:29
30,379,017
3
1
null
2015-03-30T13:32:29
2015-02-05T21:20:01
C
UTF-8
Racket
false
false
3,594
rkt
defines.rkt
#lang racket/base (provide (all-defined-out)) ;; common defines, not belonging to termios, in fact could be moved ;; somewhere (or maybe there does exist some module with them) (define EBADF 12) ;; Bad file number (define ENOTTY 25) ;; Not a typewriter ;; termios.h defined consts (define _NCCS 32) ;; c_cc characters (define VINTR 0) (define VQUIT 1) (define VERASE 2) (define VKILL 3) (define VEOF 4) (define VTIME 5) (define VMIN 6) (define VSWTC 7) (define VSTART 8) (define VSTOP 9) (define VSUSP 10) (define VEOL 11) (define VREPRINT 12) (define VDISCARD 13) (define VWERASE 14) (define VLNEXT 15) (define VEOL2 16) ;; c_iflag bits (define IGNBRK 0000001) (define BRKINT 0000002) (define IGNPAR 0000004) (define PARMRK 0000010) (define INPCK 0000020) (define ISTRIP 0000040) (define INLCR 0000100) (define IGNCR 0000200) (define ICRNL 0000400) (define IUCLC 0001000) (define IXON 0002000) (define IXANY 0004000) (define IXOFF 0010000) (define IMAXBEL 0020000) (define IUTF8 0040000) ;; c_oflag bits (define OPOST 0000001) (define OLCUC 0000002) (define ONLCR 0000004) (define OCRNL 0000010) (define ONOCR 0000020) (define ONLRET 0000040) (define OFILL 0000100) (define OFDEL 0000200) (define NLDLY 0000400) (define NL0 0000000) (define NL1 0000400) (define CRDLY 0003000) (define CR0 0000000) (define CR1 0001000) (define CR2 0002000) (define CR3 0003000) (define TABDLY 0014000) (define TAB0 0000000) (define TAB1 0004000) (define TAB2 0010000) (define TAB3 0014000) (define BSDLY 0020000) (define BS0 0000000) (define BS1 0020000) (define FFDLY 0100000) (define FF0 0000000) (define FF1 0100000) (define VTDLY 0040000) (define VT0 0000000) (define VT1 0040000) (define XTABS 0014000) ;; c_cflag bit meaning (define CBAUD 0010017) (define B0 0000000) ; /* hang up */ (define B50 0000001) (define B75 0000002) (define B110 0000003) (define B134 0000004) (define B150 0000005) (define B200 0000006) (define B300 0000007) (define B600 0000010) (define B1200 0000011) (define B1800 0000012) (define B2400 0000013) (define B4800 0000014) (define B9600 0000015) (define B19200 0000016) (define B38400 0000017) (define EXTA B19200) (define EXTB B38400) (define CSIZE 0000060) (define CS5 0000000) (define CS6 0000020) (define CS7 0000040) (define CS8 0000060) (define CSTOPB 0000100) (define CREAD 0000200) (define PARENB 0000400) (define PARODD 0001000) (define HUPCL 0002000) (define CLOCAL 0004000) (define CBAUDEX 0010000) (define B57600 0010001) (define B115200 0010002) (define B230400 0010003) (define B460800 0010004) (define B500000 0010005) (define B576000 0010006) (define B921600 0010007) (define B1000000 0010010) (define B1152000 0010011) (define B1500000 0010012) (define B2000000 0010013) (define B2500000 0010014) (define B3000000 0010015) (define B3500000 0010016) (define B4000000 0010017) (define __MAX_BAUD B4000000) (define CIBAUD 002003600000) ;/* input baud rate (not used) */ (define CMSPAR 010000000000) ;/* mark or space (stick) parity */ (define CRTSCTS 020000000000) ;/* flow control */ ;; c_lflag bits (define ISIG 0000001) (define ICANON 0000002) (define XCASE 0000004) (define ECHO 0000010) (define ECHOE 0000020) (define ECHOK 0000040) (define ECHONL 0000100) (define NOFLSH 0000200) (define TOSTOP 0000400) (define ECHOCTL 0001000) (define ECHOPRT 0002000) (define ECHOKE 0004000) (define FLUSHO 0010000) (define PENDIN 0040000) (define IEXTEN 0100000) (define EXTPROC 0200000) ;; for tcsetattr (define TCSANOW 0) (define TCSADRAIN 1) (define TCSAFLUSH 2)
false
4097d911307f2b0ec60b58e7ac575c5334f0faf6
5f792140b853f40e3c7be559c2a412d7b8296c96
/2015/day1/day1.rkt
07cad35049eaf41c384192fa4ef2ce2cc7f0deb5
[ "Unlicense" ]
permissive
winny-/aoc
9d53666faf341f1cc2016a3d21e93d7f4064a72b
f986cacf14d81d220030bca94e99ec8179861e1b
refs/heads/master
2022-12-05T00:19:47.570034
2022-12-04T09:55:11
2022-12-04T09:55:11
225,185,486
7
0
null
null
null
null
UTF-8
Racket
false
false
740
rkt
day1.rkt
#lang racket (define (f2n c) (match c [#\( 1] [#\) -1] [_ 0])) (define (read-floor input-port) (let ([char (read-char input-port)]) (if (eof-object? char) char (f2n char)))) (define (follow lst value #:index [index 0] #:accumulator [accumulator 0]) (if (null? lst) #f (begin (set! accumulator (+ (car lst) accumulator)) (if (equal? accumulator value) index (follow (cdr lst) value #:index (add1 index) #:accumulator accumulator))))) (module+ main (define lst (port->list read-floor)) (displayln (format "Santa stopped floor ~a" (apply + lst))) (displayln (format "Santa first reaches the basement at position ~a" (add1 (follow lst -1)))))
false
762f9d54ecc162820a3aa2b0d3d8fda04d1b2885
4ee29c6001c9618a1fd79bcdd1114f71bcd3f92f
/Comparative Programming Languages [H0S01a]/Exercise Session Racket/cpl_forth_solution/example.rkt
68cb68916bff3c85ac9fdc9dc10fc4c3b878463a
[]
no_license
seppeduwe/KU_Leuven_CS_Assignments
493ad0d657ce4a90d5cb81d1d90d2aa3bcee3700
260625879fc143e2d46a89ef0fa9a914a8823e10
refs/heads/master
2020-04-07T03:03:43.942855
2018-07-03T10:25:21
2018-07-03T10:25:21
45,391,827
14
5
null
null
null
null
UTF-8
Racket
false
false
61
rkt
example.rkt
#lang s-exp "language.rkt" (num 1)(num 2)(dump)(plus)(dump)
false
f727ed1902b3eeab770bde6a6f4d55392caa789b
a9651b6130a27564222706c65f0940626ef5fade
/config.rkt
b890475c64c69d1f5e5a72937c47f64552d5042c
[]
no_license
vishesh/whalebin
07cb3e60bcc5870aef785cef2c7755c899a9be4f
32043a5dcb273d128cf6adf5e95812d77d7406f2
refs/heads/develop
2020-04-27T05:49:11.547050
2015-07-06T21:04:16
2015-07-06T21:07:54
35,642,296
10
3
null
2015-08-18T18:03:13
2015-05-14T23:27:13
Racket
UTF-8
Racket
false
false
685
rkt
config.rkt
#lang racket (require (only-in web-server/http/id-cookie make-secret-salt/file)) (provide (all-defined-out)) ; Constants (define SERVER-ROOT "http://localhost:8000") (define REPO-SUBDIR-NAME-LEN 2) (define NAME-LEN 5) (define REPO-SOURCE "data/src") (define REPO-OUTPUT "data/outputs") (define DB-USER "racket") (define DB-PASSWORD "racket") (define DB-NAME "bigbang") (define SESSION-COOKIE-NAME "session") (define SESSION-COOKIE-SALT (make-secret-salt/file "SESSION-SALT")) (define STATIC-FILES-DIR "/home/vishesh/racket/whalebin/static") ; elasticsearch settings (define INDEX-NAME "whalebin") (define DOCUMENT-NAME "paste") (define ES-HOST "localhost")
false
79e24c1526bc33e66eacf92f14799d33269810ad
924ba7f58142338d2e50d19d83d5eaa2b03491c8
/musicxml/direction.rkt
ff65da729d1ca7008334e0fab0730ca3f807516d
[ "MIT" ]
permissive
AlexKnauth/musicxml
d793ca90402ae468f8389623fdf216893031a617
60018ccd9fc1867d6feebdcfa698ddb5c07cd524
refs/heads/master
2022-07-01T17:00:09.123436
2022-05-28T17:47:30
2022-05-28T17:47:30
135,214,350
0
0
null
null
null
null
UTF-8
Racket
false
false
6,078
rkt
direction.rkt
#lang racket/base (provide direction ~direction directionₑ direction-type ~direction-type direction-typeₑ ;; --- dynamics ~dynamics dynamicsₑ ;; --- metronome ~metronome metronomeₑ beat-unit beat-unit-dot per-minute ;; --- sound ~sound soundₑ ;; --- print ~print printₑ ;; --- direction-has-voice? direction-voice-string ) (require racket/contract/base racket/match syntax/parse/define (submod txexpr safe) "str-number.rkt" "note.rkt" "note-type.rkt" "voice.rkt" "note-type.rkt" "editorial.rkt" "util/tag.rkt" "util/stxparse.rkt") (define yes-no/c (or/c "yes" "no")) (define above-below/c (or/c "above" "below")) (define-syntax-class yes-no [pattern "yes"] [pattern "no"]) (define-syntax-class above-below [pattern "above"] [pattern "below"]) ;; --------------------------------------------------------- ;; Musical directions used for expression marks, such as tempo, style, ;; dynamics, etc. (define-tag direction (and/c (attrs-may/c 'placement above-below/c) (attrs-may/c 'directive yes-no/c)) (listof (or/c (tag/c direction-type) (tag/c offset) (tag/c footnote) (tag/c level) (tag/c voice) (tag/c staff) (tag/c sound)))) (define-tag direction-type '() (listof (or/c (tag/c rehearsal) (tag/c segno) (tag/c words) (tag/c coda) (tag/c wedge) (tag/c dynamics) (tag/c dashes) (tag/c bracket) (tag/c pedal) (tag/c metronome) (tag/c octave-shift) (tag/c harp-pedals) (tag/c damp) (tag/c damp-all) (tag/c eyeglasses) (tag/c string-mute) (tag/c scordatura) (tag/c image) (tag/c principal-voice) (tag/c accordion-registration) (tag/c percussion) (tag/c other-direction)))) ;; --------------------------------------------------------- (define-syntax-class directionₑ #:attributes [] #:datum-literals [placement directive] [pattern {~direction ({~alt {~optional [placement :above-below]} {~optional [directive :yes-no]}} ...) (:direction-typeₑ ...+ ;; TODO: offset :%editorial-voice {~optional :staffₑ} {~optional :soundₑ})}]) (define-syntax-class direction-typeₑ #:attributes [] [pattern {~direction-type () (:direction-type-element)}]) (define-splicing-syntax-class direction-type-element ;; TODO: rehearsal, segno, etc. [pattern {~seq :dynamicsₑ ...+}] ;; TODO: dashes, bracket, etc. [pattern {~seq :metronomeₑ}]) ;; --------------------------------------------------------- (define-simple-macro (define-empty-tags t:id ...) (begin (define-tag t '() '()) ...)) (define-tag dynamics any/c (listof (or/c (tag/c p) (tag/c pp) (tag/c ppp) (tag/c pppp) (tag/c ppppp) (tag/c pppppp) (tag/c f) (tag/c ff) (tag/c fff) (tag/c ffff) (tag/c fffff) (tag/c ffffff) (tag/c mp) (tag/c mf)))) (define-empty-tags p pp ppp pppp ppppp pppppp f ff fff ffff fffff ffffff mp mf) (define-tag metronome any/c (or/c (list/c (tag/c beat-unit) (tag/c per-minute)) (list/c (tag/c beat-unit) (tag/c beat-unit-dot) (tag/c per-minute)))) ;; How it will display. Can have any string but usually a number-ish thing (define-tag per-minute any/c (list/c string?)) ;; The sound tag can be either within a direction tag or ;; outside it as music-data by itself. ;; Currently the sound element determines the tempo when the song is played, ;; but in the future it might determine more things about how it is played ;; than just tempo. (define-tag sound (and/c (attrs-may/c 'tempo str-nonnegative-integer?) (attrs-may/c 'dynamics str-nonnegative-integer?)) '()) ;; --------------------------------------------------------- (define-syntax-class dynamicsₑ #:attributes [] [pattern {~dynamics _ (:dynamics-element ...)}]) (define-syntax-class dynamics-element #:attributes [] [pattern {~p () ()}] [pattern {~pp () ()}] [pattern {~ppp () ()}] [pattern {~pppp () ()}] [pattern {~ppppp () ()}] [pattern {~pppppp () ()}] [pattern {~f () ()}] [pattern {~ff () ()}] [pattern {~fff () ()}] [pattern {~ffff () ()}] [pattern {~fffff () ()}] [pattern {~ffffff () ()}] [pattern {~mp () ()}] [pattern {~mf () ()}]) ;; --------------------------------------------------------- (define-syntax-class metronomeₑ #:attributes [] [pattern {~metronome _ (b:beat-unit/dots pm:per-minuteₑ)}]) (define-syntax-class per-minuteₑ #:attributes [per-minute-string] [pattern {~per-minute () (per-minute:str)} #:attr per-minute-string (@ per-minute.string)]) (define-syntax-class soundₑ #:attributes [] [pattern {~sound _ _}]) ;; --------------------------------------------------------- (define-tag print any/c any/c) (define-syntax-class printₑ #:attributes [] ;; TODO [pattern {~print _ _}]) ;; --------------------------------------------------------- ;; private ;; Any -> Boolean (define (voice? v) (match v [(voice _ _) #true] [_ #false])) ;; direction-has-voice? : Direction -> Boolean (define (direction-has-voice? fw) (match fw [(direction _ elements) (ormap voice? elements)])) ;; direction-voice-string : Direction -> [Maybe VoiceStr] (define (direction-voice-string fw) (match fw [(direction _ (list _ ... (? voice? v) _ ...)) (voice-string v)] [_ #false])) ;; ---------------------------------------------------------
true
217cfd3b715c025be9af0a697ef499edbc9aeae3
b84e4ca83a53723611dbb82d19defa35c3d9cdcf
/lib/typed-module-lang/rep/type.rkt
2ba78576f77510680b33ffeb90dc2e258e2fb636
[]
no_license
macrotypefunctors/typed-module-lang
2cafea34270f5aad6100ff42becd2a6a522c658a
cfe5145412d06eef54df7d37c919aa49fff151de
refs/heads/master
2021-01-25T09:55:18.718123
2018-05-04T20:44:48
2018-05-04T20:44:48
123,330,705
0
0
null
null
null
null
UTF-8
Racket
false
false
5,262
rkt
type.rkt
#lang racket (provide (all-defined-out)) (require "../env/label-env.rkt") ;; An Environment has two parts: ;; * The BindingStore maps identifiers to unique "labels" ;; * The LabelEnv maps the labels to values ;; An [LabelEnvof X] has the operations: ;; label-env-lookup : [LabelEnvof X] Label -> X ;; label-env-extend : [LabelEnvof X] [Listof [List Label X]] -> [LabelEnvof X] ;; -------------------------------------------------------------- ;; a TypeDecl is one of ;; - (type-alias-decl Type) ;; - (type-opaque-decl) ;; - (data-decl [Listof Label]) ; constructors ;; - (constructor-decl Type) ; constructor type (struct type-alias-decl [type] #:prefab) (struct type-opaque-decl [] #:prefab) (struct data-decl [constructors] #:prefab) (struct constructor-decl [type] #:prefab) ;; a DeclKindEnv is a [Lenvof DeclKind] ;; a Lenv is a [Lenvof EnvBinding] ;; an EnvBinding is one of ;; - (val-binding Type) ;; - (type-binding TypeDecl) ;; - (constructor-binding Type) (struct val-binding [type]) (struct type-binding [decl]) (struct constructor-binding val-binding []) ;; Lenv Label -> TypeDecl or #f (define (lenv-lookup-type-decl G X) (match (label-env-lookup G X) [(type-binding td) td] [_ #f])) ;; Lenv Id -> Type or #f (define (lenv-lookup-val G x) (match (label-env-lookup G x) [(val-binding τ) τ] [_ #f])) ;; ------------------------------------------------------ ;; a Type is one of ;; - BaseType ;; - (Arrow [Listof Type] Type) ;; - (Forall [Listof Label] Type) ;; - (label-reference Label) (struct Int [] #:prefab) (struct Bool [] #:prefab) (struct Arrow [inputs output] #:prefab) (struct Forall [labels body] #:prefab) (struct label-reference [label] #:prefab) (define (subtype? G τ1 τ2) (subtype?/recur G τ1 τ2 subtype?)) ;; Env Type Type [Env Type Type -> Boolean] -> Boolean (define (subtype?/recur G A B recur-subtype?) (match* [A B] [[(Arrow τa-ins τa-out) (Arrow τb-ins τb-out)] (define (<: a b) (recur-subtype? G a b)) (and (andmap <: τb-ins τa-ins) (<: τa-out τb-out))] [[(Forall Xs τa-body) (Forall Ys τb-body)] (define common-labels (map fresh-label Xs)) (define G+common (label-env-extend G (map (λ (x) (list x (type-binding (type-opaque-decl)))) common-labels))) (and (= (length Xs) (length Ys)) (let ([τa-body* (type-substitute-label* G Xs common-labels)] [τb-body* (type-substitute-label* G Ys common-labels)]) (recur-subtype? G+common τa-body* τb-body*)))] ;; two identical label-reference types are equal; this handles the case of ;; two opaque types as well as preemtively matching aliases that ;; are obviously the same. if they are not identical then try to ;; reduce them by looking up type aliases. if we determine that ;; one is an opaque type, then we can fail because the only way ;; two opaque types can be the same is if they are referred to by ;; the same name. thus they should have been accepted by the ;; initial check. [[(label-reference x) (label-reference y)] #:when (label=? x y) #t] ;; TODO: would it be nicer to create a match pattern to match ;; named-references bound to type-alias-decls? [[(label-reference x) _] (=> cont) (match (lenv-lookup-type-decl G x) [(type-alias-decl A*) (recur-subtype? G A* B)] [_ (cont)])] [[_ (label-reference y)] (=> cont) (match (lenv-lookup-type-decl G y) [(type-alias-decl B*) (recur-subtype? G A B*)] [_ (cont)])] [[_ _] (equal? A B)])) ;; Env Type Type -> Boolean (define (type=? G τ1 τ2) (and (subtype? G τ1 τ2) (subtype? G τ2 τ1))) ;; --------------------------------------------------------- ;; type-label-reference-map : [X -> Y] [TypeWLabelRef X] -> [TypeWLabelRef Y] (define (type-label-reference-map f τ) (type-transform-label-reference τ (compose label-reference f))) ;; type-transform-label-reference : ;; [TypeWLabelRef X] ;; [X -> [TypeWLabelRef Y]] ;; -> ;; [TypeWLabelRef Y] ;; This equation holds: ;; (type-transform-label-reference τ label-reference) = τ (define (type-transform-label-reference τ f) (type-transform-label-reference/recur τ f type-transform-label-reference)) (define (type-transform-label-reference/recur τ f recur-ttlr) (define (ttlr-f t) (recur-ttlr t f)) (match τ [(label-reference x) (f x)] [(Arrow ins out) (Arrow (map ttlr-f ins) (ttlr-f out))] [(Forall ls body) (Forall ls (ttlr-f body))] ;; TODO: how do we know whether τ contains a ;; label-reference or not? [_ τ])) ;; type-substitute-label* : ;; Type [Listof Label] [Listof Label] -> Type (define (type-substitute-label* τ Xs-old Xs-new) (define mapping (make-immutable-hash (map cons Xs-old Xs-new))) (type-label-reference-map (λ (X) (hash-ref mapping X X)) τ)) ;; type-substitute* : ;; Type [Listof Label] [Listof Type] -> Type (define (type-substitute* τ Xs-old τs-new) (define mapping (make-immutable-hash (map cons Xs-old τs-new))) (type-transform-label-reference τ (λ (X) (hash-ref mapping X (label-reference X)))))
false
dda25a84d350aff654ee4fc2703827c9d599717d
d755de283154ca271ef6b3b130909c6463f3f553
/htdp-test/htdp/tests/convert.rkt
dcc0aa8ef15c5367afa3ba901660abfa85490211
[ "LicenseRef-scancode-unknown-license-reference", "MIT", "Apache-2.0" ]
permissive
racket/htdp
2953ec7247b5797a4d4653130c26473525dd0d85
73ec2b90055f3ab66d30e54dc3463506b25e50b4
refs/heads/master
2023-08-19T08:11:32.889577
2023-08-12T15:28:33
2023-08-12T15:28:33
27,381,208
100
90
NOASSERTION
2023-07-08T02:13:49
2014-12-01T13:41:48
Racket
UTF-8
Racket
false
false
1,891
rkt
convert.rkt
#lang racket (require htdp/testing) (require htdp/convert) ;; f2c : num -> num ;; to convert a Fahrenheit temperature into a Celsius temperature (define (f2c f) (* 5/9 (- f 32))) (define (fx y) 'xyz) #| Tests: with teach-pack convert.ss |# (= (f2c 212) 100) (= (f2c 32) 0) (= (f2c -40) -40) ;; ---------------------------------------------------------------------------- (define IN (build-path (find-system-path 'temp-dir) "convert-in.dat")) (define OUT (build-path (find-system-path 'temp-dir) "convert-out.dat")) (define (create-convert-in) (printf "212 32\n-40\n")) (define (check-convert-out) (and (= (read) 100) (= (read) 0) (= (read) -40))) (when (file-exists? IN) (delete-file IN)) (with-output-to-file IN create-convert-in) (when (file-exists? OUT) (delete-file OUT)) (convert-file IN f2c OUT) (with-input-from-file OUT check-convert-out) (check-error (convert-file IN list OUT) "convert: The conversion function must produce a number; but it produced '(212)") (check-error (convert-file IN first OUT) "first: expects non-empty list; given 212") (check-error (convert-file IN fx OUT) "convert: The conversion function must produce a number; but it produced 'xyz") (check-error (convert-file IN f2c 10) "convert-file: expects a string as third argument, given 10") ;; ---------------------------------------------------------------------------- ;; convert by repl: (convert-repl f2c) ;; type in 0 212 40 into the repl ;; ---------------------------------------------------------------------------- ;; convert by GUI (convert-gui f2c) (define (f2x x) (* x x x x)) (convert-gui f2x) ;; must result in an error ;; TEST BY HAND: (convert-gui first) ;; first is blamed but not nicely ;; TEST BY HAND: (convert-gui fx) ;; signal an error about not returning a number (generate-report)
false
e414f849f53bce6468faa4dfe4a9952a2acc1fbe
17126876cd4ff4847ff7c1fbe42471544323b16d
/beautiful-racket-demo/jsonic-demo-2/parser-test.rkt
4a5aa3368d63c330f0de210a6c5eff3a31ee3b3b
[ "MIT" ]
permissive
zenspider/beautiful-racket
a9994ebbea0842bc09941dc6d161fd527a7f4923
1fe93f59a2466c8f4842f17d10c1841609cb0705
refs/heads/master
2020-06-18T11:47:08.444886
2019-07-04T23:21:02
2019-07-04T23:21:02
196,293,969
1
0
NOASSERTION
2019-07-11T00:47:46
2019-07-11T00:47:46
null
UTF-8
Racket
false
false
682
rkt
parser-test.rkt
#lang br (require "parser.rkt" "tokenizer.rkt" brag/support rackunit) (check-equal? (parse-to-datum (apply-tokenizer-maker make-tokenizer "// line commment\n")) '(jsonic-program)) (check-equal? (parse-to-datum (apply-tokenizer-maker make-tokenizer "@$ 42 $@")) '(jsonic-program (jsonic-sexp " 42 "))) (check-equal? (parse-to-datum (apply-tokenizer-maker make-tokenizer "hi")) '(jsonic-program (jsonic-char "h") (jsonic-char "i"))) (check-equal? (parse-to-datum (apply-tokenizer-maker make-tokenizer "hi\n// comment\n@$ 42 $@")) '(jsonic-program (jsonic-char "h") (jsonic-char "i") (jsonic-char "\n") (jsonic-sexp " 42 ")))
false
18e21373373d24b83b8e55fa686ee03a439791ab
924b0a0a5d892ae9f449f0dfb5048a7672964e13
/rkt/tests/04-binop.rkt
2f70b0f4e4fef218e64d5c25747ed5a768ace9c8
[]
no_license
Santhoshkumar-p/inc
d25c1a9eb549095f50e5247436bf709b87a0bb68
6b5d66b4911dbe97262e9274bae5da3b6269bde1
refs/heads/master
2023-03-16T01:30:43.002060
2020-05-29T14:15:50
2020-05-29T14:15:50
null
0
0
null
null
null
null
UTF-8
Racket
false
false
5,791
rkt
04-binop.rkt
#lang racket (require "../src/driver.rkt") ;; WOW! I've never seem something that is more quickcheck friendly than this. ;; ;; I ended up with this file after cleaning up the tests and grouping them ;; together sanely. This is obviously a lot of redundant crap and needs to be ;; trimmed down. (add-tests "+" [(+ 1 2) => 3] [(+ 1 -2) => -1] [(+ -1 2) => 1] [(+ -1 -2) => -3] [(+ 536870911 -1) => 536870910] [(+ 536870910 1) => 536870911] [(+ -536870912 1) => -536870911] [(+ -536870911 -1) => -536870912] [(+ 536870911 -536870912) => -1] [(+ 1 (+ 2 3)) => 6] [(+ 1 (+ 2 -3)) => 0] [(+ 1 (+ -2 3)) => 2] [(+ 1 (+ -2 -3)) => -4] [(+ -1 (+ 2 3)) => 4] [(+ -1 (+ 2 -3)) => -2] [(+ -1 (+ -2 3)) => 0] [(+ -1 (+ -2 -3)) => -6] [(+ (+ 1 2) 3) => 6] [(+ (+ 1 2) -3) => 0] [(+ (+ 1 -2) 3) => 2] [(+ (+ 1 -2) -3) => -4] [(+ (+ -1 2) 3) => 4] [(+ (+ -1 2) -3) => -2] [(+ (+ -1 -2) 3) => 0] [(+ (+ -1 -2) -3) => -6] [(+ (+ (+ (+ (+ (+ (+ (+ 1 2) 3) 4) 5) 6) 7) 8) 9) => 45] [(+ 1 (+ 2 (+ 3 (+ 4 (+ 5 (+ 6 (+ 7 (+ 8 9)))))))) => 45] [(+ (+ 1 2) (+ 3 4)) => 10] [(+ (+ 1 2) (+ 3 -4)) => 2] [(+ (+ 1 2) (+ -3 4)) => 4] [(+ (+ 1 2) (+ -3 -4)) => -4] [(+ (+ 1 -2) (+ 3 4)) => 6] [(+ (+ 1 -2) (+ 3 -4)) => -2] [(+ (+ 1 -2) (+ -3 4)) => 0] [(+ (+ 1 -2) (+ -3 -4)) => -8] [(+ (+ -1 2) (+ 3 4)) => 8] [(+ (+ -1 2) (+ 3 -4)) => 0] [(+ (+ -1 2) (+ -3 4)) => 2] [(+ (+ -1 2) (+ -3 -4)) => -6] [(+ (+ -1 -2) (+ 3 4)) => 4] [(+ (+ -1 -2) (+ 3 -4)) => -4] [(+ (+ -1 -2) (+ -3 4)) => -2] [(+ (+ -1 -2) (+ -3 -4)) => -10] [(+ (+ (+ (+ (+ (+ (+ (+ 1 2) 3) 4) 5) 6) 7) 8) 9) => 45] [(+ 1 (+ 2 (+ 3 (+ 4 (+ 5 (+ 6 (+ 7 (+ 8 9)))))))) => 45] [(+ (+ (+ (+ 1 2) (+ 3 4)) (+ (+ 5 6) (+ 7 8))) (+ (+ (+ 9 10) (+ 11 12)) (+ (+ 13 14) (+ 15 16)))) => 136]) (add-tests "-" [(- 1 2) => -1] [(- 1 -2) => 3] [(- -1 2) => -3] [(- -1 -2) => 1] [(- 536870910 -1) => 536870911] [(- 536870911 1) => 536870910] [(- -536870911 1) => -536870912] [(- -536870912 -1) => -536870911] [(- 1 536870911) => -536870910] [(- -1 536870911) => -536870912] [(- 1 -536870910) => 536870911] [(- -1 -536870912) => 536870911] [(- 536870911 536870911) => 0] [(- -536870911 -536870912) => 1] [(- 1 (- 2 3)) => 2] [(- 1 (- 2 -3)) => -4] [(- 1 (- -2 3)) => 6] [(- 1 (- -2 -3)) => 0] [(- -1 (- 2 3)) => 0] [(- -1 (- 2 -3)) => -6] [(- -1 (- -2 3)) => 4] [(- -1 (- -2 -3)) => -2] [(- 0 (- -2 -3)) => -1] [(- (- 1 2) 3) => -4] [(- (- 1 2) -3) => 2] [(- (- 1 -2) 3) => 0] [(- (- 1 -2) -3) => 6] [(- (- -1 2) 3) => -6] [(- (- -1 2) -3) => 0] [(- (- -1 -2) 3) => -2] [(- (- -1 -2) -3) => 4] [(- (- (- (- (- (- (- (- 1 2) 3) 4) 5) 6) 7) 8) 9) => -43] [(- 1 (- 2 (- 3 (- 4 (- 5 (- 6 (- 7 (- 8 9)))))))) => 5] [(- (- 1 2) (- 3 4)) => 0] [(- (- 1 2) (- 3 -4)) => -8] [(- (- 1 2) (- -3 4)) => 6] [(- (- 1 2) (- -3 -4)) => -2] [(- (- 1 -2) (- 3 4)) => 4] [(- (- 1 -2) (- 3 -4)) => -4] [(- (- 1 -2) (- -3 4)) => 10] [(- (- 1 -2) (- -3 -4)) => 2] [(- (- -1 2) (- 3 4)) => -2] [(- (- -1 2) (- 3 -4)) => -10] [(- (- -1 2) (- -3 4)) => 4] [(- (- -1 2) (- -3 -4)) => -4] [(- (- -1 -2) (- 3 4)) => 2] [(- (- -1 -2) (- 3 -4)) => -6] [(- (- -1 -2) (- -3 4)) => 8] [(- (- -1 -2) (- -3 -4)) => 0] [(- (- (- (- (- (- (- (- 1 2) 3) 4) 5) 6) 7) 8) 9) => -43] [(- 1 (- 2 (- 3 (- 4 (- 5 (- 6 (- 7 (- 8 9)))))))) => 5] [(- (- (- (- 1 2) (- 3 4)) (- (- 5 6) (- 7 8))) (- (- (- 9 10) (- 11 12)) (- (- 13 14) (- 15 16)))) => 0]) (add-tests "*" [(* 2 3) => 6] [(* 2 -3) => -6] [(* -2 3) => -6] [(* -2 -3) => 6] [(* 536870911 1) => 536870911] [(* 536870911 -1) => -536870911] [(* -536870912 1) => -536870912] [(* -536870911 -1) => 536870911] [(* 2 (* 3 4)) => 24] [(* (* 2 3) 4) => 24] [(* (* (* (* (* 2 3) 4) 5) 6) 7) => 5040] [(* 2 (* 3 (* 4 (* 5 (* 6 7))))) => 5040]) (add-tests "=" [(= 12 13) => #f] [(= 12 12) => #t] [(= 16 (+ 13 3)) => #t] [(= 16 (+ 13 13)) => #f] [(= (+ 13 3) 16) => #t] [(= (+ 13 13) 16) => #f]) (add-tests "<" [(< 12 13) => #t] [(< 12 12) => #f] [(< 13 12) => #f] [(< 16 (+ 13 1)) => #f] [(< 16 (+ 13 3)) => #f] [(< 16 (+ 13 13)) => #t] [(< (+ 13 1) 16) => #t] [(< (+ 13 3) 16) => #f] [(< (+ 13 13) 16) => #f]) (add-tests "<=" [(<= 12 13) => #t] [(<= 12 12) => #t] [(<= 13 12) => #f] [(<= 16 (+ 13 1)) => #f] [(<= 16 (+ 13 3)) => #t] [(<= 16 (+ 13 13)) => #t] [(<= (+ 13 1) 16) => #t] [(<= (+ 13 3) 16) => #t] [(<= (+ 13 13) 16) => #f]) (add-tests ">" [(> 12 13) => #f] [(> 12 12) => #f] [(> 13 12) => #t] [(> 16 (+ 13 1)) => #t] [(> 16 (+ 13 3)) => #f] [(> 16 (+ 13 13)) => #f] [(> (+ 13 1) 16) => #f] [(> (+ 13 3) 16) => #f] [(> (+ 13 13) 16) => #t]) (add-tests ">=" [(>= 12 13) => #f] [(>= 12 12) => #t] [(>= 13 12) => #t] [(>= 16 (+ 13 1)) => #t] [(>= 16 (+ 13 3)) => #t] [(>= 16 (+ 13 13)) => #f] [(>= (+ 13 1) 16) => #f] [(>= (+ 13 3) 16) => #t] [(>= (+ 13 13) 16) => #t]) (add-tests "log {and, or, not}" [(logand 3 7) => 3] [(logand 3 5) => 1] [(logand 2376 2376) => 2376] [(logand 2346 (lognot 2346)) => 0] [(logand (lognot 2346) 2346) => 0] [(logand (lognot (lognot 12)) (lognot (lognot 12))) => 12] [(logand (lognot (lognot 12)) (lognot (lognot 12))) => 12] [(lognot (logor (lognot 7) 1)) => 6] [(lognot (logor 1 (lognot 7))) => 6] [(logor 3 16) => 19] [(logor 3 5) => 7] [(logor 3 7) => 7]) (add-tests "remainder/modulo/quotient" [(quotient 16 4) => 4] [(quotient 5 2) => 2] [(quotient -45 7) => -6] [(quotient 10 -3) => -3] [(quotient -17 -9) => 1] [(remainder 16 4) => 0] [(remainder 5 2) => 1] [(remainder -45 7) => -3] [(remainder 10 -3) => 1] [(remainder -17 -9) => -8])
false
5949a07a7231541172de4c0ee03ca5b37316365b
96e1bbef7bb0b8cb31355727902d1df15a04cb60
/sicp/little/number_cans.rkt
b70dda8c3f7981be1908232add90decf76463114
[]
no_license
qig123/racket_ex
14acff1e7adcbc1e04001a7bf86c5c8888b73176
e71035ae5fee90d60550a4b0d8fa5cca6dd33c73
refs/heads/master
2022-08-11T22:13:49.503482
2022-07-23T09:07:08
2022-07-23T09:07:08
216,301,835
0
0
null
null
null
null
UTF-8
Racket
false
false
3,500
rkt
number_cans.rkt
#lang Racket (provide add1) (provide +) (provide ×) (provide ÷) (provide -) (provide eqan?) (define add1 (lambda (n) (+ n 1) ) ) (define sub1 (lambda (n) (- n 1) ) ) (define + (lambda (n m) (cond ((zero? m) n) (else (add1 (+ n (sub1 m) ))) ) ) ) ;define sub (define - (lambda (n m) (cond ((zero? m) n) (else (sub1 (- n (sub1 m)))) ) ) ) ;define addtup (define addtup (lambda (tup) (cond ((null? tup) 0) (else (+ (car tup) (addtup (cdr tup)))) ) ) ) (define × (lambda (n m) (cond ((zero? m) 0) (else (+ n (× n (sub1 m)))) ) ) ) ;tup+ (define tup+ (lambda (tup1 tup2) (cond ((null? tup1) tup2) ((null? tup2) tup1) (else (cons (+ (car tup1) (car tup2)) (tup+ (cdr tup1 ) (cdr tup2))) ) ) ) ) ;define > using zero? sub1 (define > (lambda (n m) (cond ((zero? n) #f ) ((zero? m) #t ) (else (> (sub1 n) (sub1 m))) ) ) ) (define < (lambda (n m) (cond ((zero? m) #f ) ((zero? n) #t ) (else (< (sub1 n) (sub1 m))) ) ) ) ; (define equal (lambda (n m) (cond ((zero? m) (zero? n)) ((zero? n) #f) (else (equal (sub1 n) (sub1 m))) ) ) ) (define eq2 (lambda (n m) (cond ((> n m) #f) ((< n m) #f) (else #t) ) ) ) ;first and fif comand (define exp2 (lambda (n m) (cond ((zero? m) 1) (else (× n (exp2 n (sub1 m)))) ) ) ) (define ÷ (lambda (n m) (cond ((< n m) 0) (else (add1 (÷ (- n m) m))) ) ) ) (define length (lambda (lst) (cond ((null? lst) 0) (else (add1 (length (cdr lst)))) ) ) ) (define pick (lambda ( n lat) (cond ((null? lat) '()) (else (cond ((equal 1 n) (car lat)) (else (pick (sub1 n) (cdr lat)) ) ) ) ))) (define rempick (lambda (n lat) (cond ((null? lat) '()) (else (cond ((zero? (sub1 n)) (rempick (sub1 n) (cdr lat))) (else (cons (car lat) (rempick (sub1 n) (cdr lat)))) ) ) ) ) ) (define rempick2 (lambda (n lat) (cond ((zero? (sub1 n)) (cdr lat)) (else (cons (car lat) (rempick2 (sub1 n) (cdr lat)))) ) ) ) ;(no_nums (list 5 'pears 6 'prunes 9 'dates)) (define no_nums (lambda (lat) (cond ((null? lat) '()) (else (cond ((number? (car lat)) (no_nums (cdr lat))) (else (cons (car lat) (no_nums (cdr lat))) ) ) ) ) ) ) (define all_nums (lambda (lat) (cond ((null? lat) '()) (else (cond ( (not (number? (car lat))) (all_nums (cdr lat))) (else (cons (car lat) (all_nums (cdr lat))) ) ) ) ) ) ) (define eqan? (lambda (a1 a2) (cond ((and (number? a1) (number? a2)) (equal a1 a2)) ((or (number? a1) (number? a2)) #f) (else (eq? a1 a2)) ) ) ) (define occur (lambda (a lat) (cond ((null? lat) 0) (else (cond ((eqan? a (car lat)) (add1 (occur a (cdr lat))) ) (else (occur a (cdr lat)) ) ) ) ) )) (define one? (lambda (n) (= n 1) ) )
false
59eee745d8ebd1ad39b43760b6df37e83a38c58c
ffba88a180b2b7ee0a2a1e76399b823201b7328e
/examples/test-demo.rkt
b050271eb0880b7be31c96331e7149ab3b2f1c10
[ "MIT", "Apache-2.0" ]
permissive
yjqww6/racket-annotator
71952f53a9704d8ee0f116b403b7bce07c1b68c3
f97ce5324ff86392a6b004cbcb3e801bf1e04dbe
refs/heads/master
2022-12-27T22:06:26.621488
2020-10-14T03:32:49
2020-10-14T03:32:49
298,212,626
0
0
null
null
null
null
UTF-8
Racket
false
false
114
rkt
test-demo.rkt
#lang s-exp "demo.rkt" (for ([i (in-range 10)]) (void)) (module+ main (for ([i (in-range 10)]) (void)))
false
719e9024e3668e698511528809892bc8dce096eb
b08b7e3160ae9947b6046123acad8f59152375c3
/Programming Language Detection/Experiment-2/Dataset/Train/Racket/i-before-e-except-after-c.rkt
bcb8926d3b2433a0acbcb9b48d059692529e6982
[]
no_license
dlaststark/machine-learning-projects
efb0a28c664419275e87eb612c89054164fe1eb0
eaa0c96d4d1c15934d63035b837636a6d11736e3
refs/heads/master
2022-12-06T08:36:09.867677
2022-11-20T13:17:25
2022-11-20T13:17:25
246,379,103
9
5
null
null
null
null
UTF-8
Racket
false
false
1,427
rkt
i-before-e-except-after-c.rkt
#lang racket (define (get-tallies filename line-parser . patterns) (for/fold ([totals (make-list (length patterns) 0)]) ([line (file->lines filename)]) (match-let ([(list word n) (line-parser line)]) (for/list ([p patterns] [t totals]) (if (regexp-match? p word) (+ n t) t))))) (define (plausible test) (string-append (if test "" "IM") "PLAUSIBLE")) (define (subrule description examples counters) (let ([result (> examples (* 2 counters))]) (printf " The sub-rule \"~a\" is ~a. There were ~a examples and ~a counter-examples.\n" description (plausible result) examples counters) result)) (define (plausibility description filename parser) (printf "~a:\n" description) (match-let ([(list cei cie ie ei) (get-tallies filename parser "cei" "cie" "ie" "ei")]) (let ([rule1 (subrule "I before E when not preceded by C" (- ie cie) (- ei cei))] [rule2 (subrule "E before I when preceded by C" cei cie)]) (printf "\n Overall, the rule \"I before E, except after C\" is ~a.\n" (plausible (and rule1 rule2)))))) (define (parse-frequency-data line) (let ([words (string-split line)]) (list (string-join (drop-right words 2)) (string->number (last words))))) (plausibility "Dictionary" "unixdict.txt" (λ (line) (list line 1))) (newline) (plausibility "Word frequencies (stretch goal)" "1_2_all_freq.txt" parse-frequency-data)
false
1da4f1cfb530a6cae4121de67896dc4c425396fb
51a53a16e2ab9fe5cfae68b5710788db7d9dd1f3
/private/assertions.rkt
3416dd17af55a30d7d038008bc899389d6e8e7c6
[]
no_license
spdegabrielle/inference
09b41c4af9cfee2be36c3a20bdcbed551f69f87c
b407fd29d0a82f3262ddd9ced3259117b9448f40
refs/heads/master
2021-01-20T05:54:24.793208
2013-10-14T20:19:09
2013-10-14T20:19:09
null
0
0
null
null
null
null
UTF-8
Racket
false
false
5,725
rkt
assertions.rkt
#lang racket ;;; PLT Scheme Inference Collection ;;; assertions.rkt ;;; Copyright (c) 2006-2010 M. Douglas Williams ;;; ;;; This library is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU Lesser General Public ;;; License as published by the Free Software Foundation; either ;;; version 2.1 of the License, or (at your option) any later version. ;;; ;;; This library is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; Lesser General Public License for more details. ;;; ;;; You should have received a copy of the GNU Lesser General Public ;;; License along with this library; if not, write to the Free ;;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA ;;; 02111-1307 USA. ;;; ;;; ----------------------------------------------------------------------------- ;;; ;;; Assertions represent facts in the knowledge base. Each has a uniqie id, the ;;; fact itself, and a reason (source would have been a better term). ;;; ;;; The only use of list operation is for assertions-subset? and are ;;; verified to be immutable. ;;; ;;; Version Date Comments ;;; 1.0.1 07/22/06 Added custom printing for assertion structs. (Doug ;;; Williams) ;;; 2.0.0 06/25/08 Changes for V4.0. (Doug Williams) ;;; 2.0.1 07/02/08 Verified immutability of lists. Updated header. (Doug ;;; Williams) ;;; 2.0.2 12/25/08 Added module contracts and other code cleanup. (Doug ;;; Williams) ;;; 2.0.3 10/01/11 Changed assertion print to truncate to (error-print-width) ;;; characters. (MDW) (require "inference-environments.ss" "facts.ss") ;;; ----------------------------------------------------------------------------- ;;; Assertions ;;; ----------------------------------------------------------------------------- ;;; (assertion-print assertion port write?) -> any/c ;;; Prints a readable form of an assertion to the specified port. This is used as ;;; custom write procedure for assertions. (define (assertion-print assertion port write?) (when write? (write-string "<" port)) (if write? (fprintf port "assertion-~a: ~.s" (assertion-id assertion) (assertion-fact assertion)) (fprintf port "assertion-~a: ~.s" (assertion-id assertion) (assertion-fact assertion))) (when (assertion-reason assertion) (fprintf port " : ~.s" (assertion-reason assertion))) (when write? (write-string ">" port))) ;;; (struct assertion (id fact reason)) ;;; id : exact-nonnegative-integer? ;;; fact : fact? ;;; reason : any/c ;;; Each instance represents an assertion in the knowledge base. Uses make- ;;; struct-type to create the structure type to allow a special make-assertion ;;; function to be written. (define-values (struct:assertion assertion-constructor assertion? assertion-field-ref set-assertion-field!) (make-struct-type 'assertion #f 3 0 #f (list (cons prop:custom-write assertion-print)) (make-inspector))) ;;; id field (define assertion-id (make-struct-field-accessor assertion-field-ref 0 'id)) (define set-assertion-id! (make-struct-field-mutator set-assertion-field! 0 'id)) ;;; fact field (define assertion-fact (make-struct-field-accessor assertion-field-ref 1 'fact)) (define set-assertion-fact! (make-struct-field-mutator set-assertion-field! 1 'fact)) ;;; reason field (define assertion-reason (make-struct-field-accessor assertion-field-ref 2 'reason)) (define set-assertion-reason! (make-struct-field-mutator set-assertion-field! 2 'reason)) ;;; (make-assertion fact reason) -> assertion? ;;; fact : any/c ;;; reason : any/c ;;; Returns a new assertion with the specified fact and reason. The next id is ;;; used. (define (make-assertion fact reason) (let ((assertion (assertion-constructor (current-inference-next-assertion-id) fact reason))) (current-inference-next-assertion-id (+ (current-inference-next-assertion-id) 1)) assertion)) ;;; (assertions-subset? assertions-1 assertions-2) -> boolean? ;;; assertions-1 : (listof assertion?) ;;; assertions-2 : (listof assertion?) ;;; Returns #t if the first list of assertions is a subset of the second. Used ;;; to implement match-subset?. (define (assertions-subset? assertions-1 assertions-2) (cond ((null? assertions-1) #t) ((null? assertions-2) #f) ((not (eq? (car assertions-1) (car assertions-2))) #f) (else (assertions-subset? (cdr assertions-1) (cdr assertions-2))))) ;;; ----------------------------------------------------------------------------- ;;; Module Contracts ;;; ----------------------------------------------------------------------------- ;(provide/contract ; (assertion? ; (-> any/c boolean?)) ; (make-assertion ; (-> fact? any/c assertion?)) ; (assertion-id ; (-> assertion? exact-nonnegative-integer?)) ; (assertion-fact ; (-> assertion? fact?)) ; (set-assertion-fact! ; (-> assertion? fact? void?)) ; (assertion-reason ; (-> assertion? any)) ; (set-assertion-reason! ; (-> assertion? any/c void?)) ; (assertions-subset? ; (-> (listof assertion?) (listof assertion?) boolean?))) (provide (all-defined-out))
false
2550dbe50e086a99d2fe16bcff4e38ccebb3147c
69e94593296c73bdfcfc2e5a50fea1f5c5f35be1
/Tutorials/Tut2/q17.rkt
f00fc8b769425da0b49c58eaddc2fd5985028b94
[]
no_license
nirajmahajan/CS152
7e64cf4b8ec24ed9c37ecc72c7731816089e959b
ef75b37715422bf96648554e74aa5ef6e36b9eb3
refs/heads/master
2020-05-29T18:02:08.993097
2019-05-29T20:35:06
2019-05-29T20:35:06
189,293,837
0
0
null
null
null
null
UTF-8
Racket
false
false
263
rkt
q17.rkt
#lang racket (define (rle l) (define (op x y) (cond [(null? y) (cons (list x 1) y)] [(= x (caar y)) (cons (list (caar y) (+ 1(cadar y))) (cdr y))] [else (cons (list x 1) y)])) (reverse (foldl op '() l)))
false
9e09797bc572483e09547a549a418413de6bd4ca
b9eb119317d72a6742dce6db5be8c1f78c7275ad
/wc/racket/q.rkt
ea4dee9d1e043ddfe255b8cab9a7a3786366a0c6
[]
no_license
offby1/doodles
be811b1004b262f69365d645a9ae837d87d7f707
316c4a0dedb8e4fde2da351a8de98a5725367901
refs/heads/master
2023-02-21T05:07:52.295903
2022-05-15T18:08:58
2022-05-15T18:08:58
512,608
2
1
null
2023-02-14T22:19:40
2010-02-11T04:24:52
Scheme
UTF-8
Racket
false
false
656
rkt
q.rkt
#lang racket ;; Functional queue made from two stacks. (struct queue (forward reverse)) (provide make-queue) (define (make-queue) (queue '() '())) (provide enqueue) (define (enqueue q item) (queue (queue-forward q) (cons item (queue-reverse q)))) (provide dequeue) (define (dequeue q) (if (null? (queue-forward q)) (dequeue (queue (reverse (queue-reverse q)) '())) (values (car (queue-forward q)) (queue (cdr (queue-forward q)) (queue-reverse q))))) (provide queue-empty?) (define (queue-empty? q) (and (null? (queue-forward q)) (null? (queue-reverse q))))
false
c24885dbdee43e425c9ea869f08c4961666e2300
d17943098180a308ae17ad96208402e49364708f
/platforms/js-vm/private/tests/moby-programs/sierpinski.rkt
655eefd952e3c3350bc65c402ba7d995ae016fa5
[]
no_license
dyoo/benchmark
b3f4f39714cc51e1f0bc176bc2fa973240cd09c0
5576fda204529e5754f6e1cc8ec8eee073e2952c
refs/heads/master
2020-12-24T14:54:11.354541
2012-03-02T19:40:48
2012-03-02T19:40:48
1,483,546
1
0
null
null
null
null
UTF-8
Racket
false
false
206
rkt
sierpinski.rkt
#lang s-exp "../../lang/wescheme.rkt" "sierpinski" (let sierpinski ([n 6]) (if (zero? n) (triangle 10 'solid 'red) (let ([next (sierpinski (- n 1))]) (above next (beside next next)))))
false
1f5c3b9b67e7ceb011b29b57b8dbb72b674b31d4
f05faa71d7fef7301d30fb8c752f726c8b8c77d4
/src/exercises/ex-3.74.rkt
07935dd6f38cd69fe6468d1e0dfe74a62f56543f
[]
no_license
yamad/sicp
c9e8a53799f0ca6f02b47acd23189b2ca91fe419
11e3a59f41ed411814411e80f17606e49ba1545a
refs/heads/master
2021-01-21T09:53:44.834639
2017-02-27T19:32:23
2017-02-27T19:32:23
83,348,438
1
0
null
null
null
null
UTF-8
Racket
false
false
2,363
rkt
ex-3.74.rkt
#lang racket (require "../examples/streams.rkt") (require "ex-3.50.rkt") ;; Exercise 3.74: Alyssa P. Hacker is designing a system to process ;; signals coming from physical sensors. One important feature she ;; wishes to produce is a signal that describes the "zero crossings" ;; of the input signal. That is, the resulting signal should be + 1 ;; whenever the input signal changes from negative to positive, - 1 ;; whenever the input signal changes from positive to negative, and 0 ;; otherwise. (Assume that the sign of a 0 input is positive.) For ;; example, a typical input signal with its associated zero-crossing ;; signal would be ;; ;; ... 1 2 1.5 1 0.5 -0.1 -2 -3 -2 -0.5 0.2 3 4 ... ;; ... 0 0 0 0 0 -1 0 0 0 0 1 0 0 ... ;; ;; In Alyssa's system, the signal from the sensor is represented as a ;; stream `sense-data' and the stream `zero-crossings' is the ;; corresponding stream of zero crossings. Alyssa first writes a ;; procedure `sign-change-detector' that takes two values as arguments ;; and compares the signs of the values to produce an appropriate 0, ;; 1, or - 1. She then constructs her zero-crossing stream as ;; follows: ;; ;; (define (make-zero-crossings input-stream last-value) ;; (cons-stream ;; (sign-change-detector (stream-car input-stream) last-value) ;; (make-zero-crossings (stream-cdr input-stream) ;; (stream-car input-stream)))) ;; ;; (define zero-crossings (make-zero-crossings sense-data 0)) ;; ;; Alyssa's boss, Eva Lu Ator, walks by and suggests that this program ;; is approximately equivalent to the following one, which uses the ;; generalized version of `stream-map' from Exercise 3-50 ;; ;; (define zero-crossings ;; (stream-map sign-change-detector sense-data <EXPRESSION>)) ;; ;; Complete the program by supplying the indicated <EXPRESSION>. (define (sign-change-detector a b) (cond ((or (null? a) (null? b)) 0) ((and (negative? a) (positive? b)) 1) ((and (positive? a) (negative? b)) -1) (else 0))) (define sense-data (list-to-stream '(1 2 1.5 1 0.5 -0.1 -2 -3 -2 -0.5 -.2 3 4))) (define zero-crossings (stream-map-multiple sign-change-detector sense-data (stream-cdr sense-data))) (provide sign-change-detector sense-data)
false
985ffa7440b56759e1bfffec2df00f1aebc080af
82c76c05fc8ca096f2744a7423d411561b25d9bd
/typed-racket-test/fail/ht-infer.rkt
1e5eed96cab3d991d8b4d91c6c20253d03ef4ad3
[ "MIT", "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
racket/typed-racket
2cde60da289399d74e945b8f86fbda662520e1ef
f3e42b3aba6ef84b01fc25d0a9ef48cd9d16a554
refs/heads/master
2023-09-01T23:26:03.765739
2023-08-09T01:22:36
2023-08-09T01:22:36
27,412,259
571
131
NOASSERTION
2023-08-09T01:22:41
2014-12-02T03:00:29
Racket
UTF-8
Racket
false
false
606
rkt
ht-infer.rkt
#lang scheme/load (module before typed/scheme (provide (all-defined-out)) (define-struct: Sigil ()) (: list->english ((Listof String) -> String)) (define (list->english strs) (error 'fail)) (define-type-alias (Set X) (HashTable X '())) (: empty-set (All (T) (-> (Set T)))) (define (empty-set) (error 'fail)) (: set->list (All (T) ((Set T) -> (Listof T)))) (define (set->list set) (error 'fail)) ) (module after typed/scheme (require 'before) (: f ((Set Sigil) -> Any)) (define (f x1) (let* ([x2 (set->list x1)]) (list->english x2) (error 'NO! "Way!"))))
false
a5b06b47d4c8e8a25fff66b2c0a8e4dfa7b692ea
d755de283154ca271ef6b3b130909c6463f3f553
/htdp-lib/lang/plt-pretty-big.rkt
ceefde078ab1fa6ca6f6d5632bad554f2885b867
[ "Apache-2.0", "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
racket/htdp
2953ec7247b5797a4d4653130c26473525dd0d85
73ec2b90055f3ab66d30e54dc3463506b25e50b4
refs/heads/master
2023-08-19T08:11:32.889577
2023-08-12T15:28:33
2023-08-12T15:28:33
27,381,208
100
90
NOASSERTION
2023-07-08T02:13:49
2014-12-01T13:41:48
Racket
UTF-8
Racket
false
false
210
rkt
plt-pretty-big.rkt
(module plt-pretty-big "plt-pretty-big-text.rkt" (require mred "private/imageeq.rkt") (provide (all-from "plt-pretty-big-text.rkt") (all-from mred) (all-from "private/imageeq.rkt")))
false
1a147f5e271325d77722045194f12379deee98a2
c203473850e4346f403ec4b2112cee5723466704
/assignment2/3007a2q4.rkt
3679be5561b3eb64f5797b1dac6a031bdfbfa364
[]
no_license
quddd/3007
b02346ddc14136997b684008b97d9f5a2647cf9b
468212e683400694bf42d63537d1038917a0567a
refs/heads/master
2020-05-25T02:27:03.740181
2019-05-20T06:20:33
2019-05-20T06:20:33
187,579,344
0
0
null
null
null
null
UTF-8
Racket
false
false
1,152
rkt
3007a2q4.rkt
;-------QUDUS AGBALAYA (Prince)----------- ;-------3007 Assignment2------------------ (#%require (only racket/base random)) (define (rps) (define (display-score n) (display "Your score is: ") (display n)(newline)) (define (play uscore count) (display " Input 0 for Rock, 1 for Paper, 2 for Scissors. Three rounds per game")(newline) (define user-input (read)) (define comp-input (random 3)) (display "Computer chose:") (display comp-input)(newline) ;Check who beats who ;----------------------- (cond ((and (= user-input 0) (= comp-input 2))(+ uscore 1)) ((and (= user-input 1) (= comp-input 0))(+ uscore 1)) ((and (= user-input 2) (= comp-input 1))(+ uscore 1)) ((= user-input comp-input)(+ uscore 0)) (else (- uscore 1))) (display-score uscore)(newline) (if (< count 3) (play uscore (+ count 1)) (display-score uscore))) (display "-----------------------------------------------")(newline) (display "------------- Rock, Paper, Scissors------------")(newline) (define user-score 0) (display-score user-score) (play user-score 1) )
false
2ebc71e45f4684dfbfb4ae5a8333142c30926624
ef61a036fd7e4220dc71860053e6625cf1496b1f
/HTDP2e/01-fixed-size-data/intermezzo-1-bsl/ex-125-def-struct-discrimination.rkt
389b23da9e91f3024835323b132209821df84695
[]
no_license
lgwarda/racket-stuff
adb934d90858fa05f72d41c29cc66012e275931c
936811af04e679d7fefddc0ef04c5336578d1c29
refs/heads/master
2023-01-28T15:58:04.479919
2020-12-09T10:36:02
2020-12-09T10:36:02
249,515,050
0
0
null
null
null
null
UTF-8
Racket
false
false
862
rkt
ex-125-def-struct-discrimination.rkt
;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname ex-125-def-struct-discrimination) (read-case-sensitive #t) (teachpacks ((lib "universe.rkt" "teachpack" "2htdp") (lib "image.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "universe.rkt" "teachpack" "2htdp") (lib "image.rkt" "teachpack" "2htdp")) #f))) ; Both 1 and 2 are legal sentences. 1 because define-struct is followed by a single variable name and ; 2 since child, parents, dob, and date are variables and the parentheses are placed according to ; the grammatical pattern. 3 doesn't contain a single variable name and parentheses aren't ; according to the gramatical pattern.
false