dedbox / racket-algebraic Goto Github PK
View Code? Open in Web Editor NEWAlgebraic structures for untyped Racket
License: MIT License
Algebraic structures for untyped Racket
License: MIT License
Already passing ...
and ...+
through unaltered. What else?
That's it for now.
Right now, it only works for references into racket/base.
top level patterns already implemented
A core calculus with functions, macros, and constructors.
1 of 3
"Fast enough for me" is not a viable long term strategy. Eventually, I would like to automatically generate reports through raco
whatever to help answer the following questions:
General Questions:
Ongoing Concerns:
#lang racket
with algebraic structuresThe next release brings three major updates:
match
and syntax-parse
Most of the work will be for number 3.
We need more information to make any sort of meaningful decision. What must it provide to be useful? Are there any examples that clearly demonstrates its utility? Does it have any unique or surprising qualities? What does any of this have to do with language-oriented programming?
For multi-arg, single-clause abstractions, so I can do something like this:
(define-syntax app (μ* (f x ...) (call-with-values (λ () (values x ...)) f)))
Like #:if patterns, but the target is a pattern instead of an expression.
Example:
(φ (Some v1) #:as v #:if (number? v1) (+ v 1))
Which ones: void, vector, box, struct, quasiquote
so (phi (p #:if t) e)
can be written as (phi p #:if t e)
and
(function
[(p1 #:if t1) e1]
[(p2 #:if t2) e2])
can be shortened to
(function
[p1 #:if t1 e1]
[p2 #:if t2 e2])
They're already implemented.
Doesn't work:
(define-syntax q-power
(macro*
[(0 _) 1]
[(1 x) x]
[(n:nat x) #'#,(macro-expand #`(* x (q-power #,(- (var n) 1) x)))]))
(q-power 3 2)
Gives this error:
/tmp/f.rkt:12:15: quote-syntax: cannot use identifier tainted by macro transformation
in: quote-syntax
location...:
/tmp/f.rkt:12:15
context...:
raise-syntax-error
binding-lookup50
loop
/usr/share/racket/collects/racket/private/template.rkt:199:4: parse-t-pair/command
/usr/share/racket/collects/racket/private/template.rkt:330:4: parse-h
/usr/share/racket/collects/racket/private/template.rkt:275:4: parse-t-pair/normal
[repeats 3 more times]
/usr/share/racket/collects/racket/private/template.rkt:177:2: parse-template
/usr/share/racket/collects/racket/private/template.rkt:577:0: syntax
apply-transformer-in-context
apply-transformer52
dispatch-transformer41
do-local-expand50
/usr/share/racket/collects/syntax/wrap-modbeg.rkt:46:4: do-wrapping-module-begin
apply-transformer-in-context
apply-transformer52
...
Doesn't work:
(let ([a 1]) ((μ x x) a))
Gives this error:
; cannot reference an identifier before its definition
; in module: top-level
; internal name: a
; Context:
; "/home/eric/work/racket-algebraic/rb-test.rkt":1:1 [running body]```
Shouldn't work:
(struct S ())
((φ #hash([x . (S)]) 1) (hasheq 'x (S)))
Either detect the kind of hash coming in or provide #hasheq/... patts as well.
Provide algebraic variants of forms like let
, for
, case
, ...
Right now, regexps can only accept or reject a string:
((φ #rx"^(x+)$" 1) "xxxx")
It should also match an optional pattern list against the results:
f.rkt> ((φ (#rx"(x+)(y+)" xs ys) xs) "aaaaxxxxyyyybbbb")
"xxxx"
Right now, #hash([x . 1])
matches a hash with at least the one binding. Instead, it should match a hash with only the one binding.
Inexact match should be denoted with a hanging wildcard, like it already is for instances or pairs:
(φ #hash([x . 1] . _) OK)
Other forms: struct, regexp, vector (?)
and
, list
, ...
Use the struct type info to validate field names and then translate to short form.
So slow...
Doesn't deconstruct or capture variables right now.
Implement patterns for destructuring lists and other immutable data:
boolean, number, string, bytes, char, symbol, regexp, keyword, pair, list, vector, box, hash, void, struct
and document the process
This fails because the constructor S has not been declared yet.
base.rkt> ((φ `(x y . ,S) z) '(x y . S))
; stdin::7109: quasiquote: bad syntax
; in: quasiquote
; Context:
; /usr/share/racket/collects/racket/syntax.rkt:195:0 syntax-local-eval24
; /usr/share/racket/collects/syntax/parse/private/parse.rkt:158:7 parse-con-id34
; /usr/share/racket/collects/syntax/parse/define.rkt:13:9 φ
In addition to generic ones like pattern
and product
, consider providing a whole library of convenient classes like int
and box
vector, box, hash
The labels for the API reference are leaking into core-example
outputs.
Ideally, it'll look like the output of core-code
with a #lang algebraic/model/core
at the top.
How to circumvent underscore->italics for racket identifiers in examples?
delimited '.' - where else can this notation go?
``Borrowing'' features from the host platform.
3 of 3
partially implemented
Matching on #s literals fails because the prefab struct key is inside a custom reader. Here's how far I got before punting:
(define-syntax-class prefab
#:description "prefab struct pattern"
#:attributes (match-pat)
(pattern x:expr
#:when (struct? (syntax-e #'x))
#:with key (prefab-struct-key (syntax-e #'x))
#:with (p:patt ...) (struct->list (syntax-e #'x))
#:attr match-pat
#'(app (λ (s) (and (struct? s)
(equal? (prefab-struct-key s) ???)
???)))))
The function
and meta-function
macros use the new ~?
and ~@
patterns, which breaks compatibility with Racket 6.12. So far, I'm pretty happy with Racket 7.0. Is it worth the trouble to back-port?
Got:
f.rkt> ((φ (F [a x] [b y]) (list x y)) (F 2 3))
; stdin::6191: struct*: not a structure definition
; at: F
; in: (struct* F ((a x) (b y)))
; Context:
; /usr/share/racket/collects/racket/match/struct.rkt:10:2
; /usr/share/racket/collects/syntax/apply-transformer.rkt:8:0
; /usr/share/racket/collects/syntax/apply-transformer.rkt:18:0 local-apply-transformer5
; /usr/share/racket/collects/racket/match/parse-helper.rkt:168:0 match-expander-transform
; /usr/share/racket/collects/racket/match/gen-match.rkt:54:23 for-loop
; /usr/share/racket/collects/racket/match/gen-match.rkt:53:11 mk
; /usr/share/racket/collects/racket/match/gen-match.rkt:44:9 for-loop
; /usr/share/racket/collects/racket/match/../../syntax/parse/private/parse.rkt:1040:13 dots-loop
; /usr/share/racket/collects/racket/match/gen-match.rkt:23:0 go
An extended syntax for the core calculus.
2 of 3
The match
doc has a (quote datum)
case:
Right now, it's just full-width
and grammar-style
.
For functions AND macros:
Make the pattern _x _y _x
match 1 2 1
but not 1 2 3
, and make sure the pattern _ _ _
still matches 1 2 3
.
It could be done by making named wildcards normal variables in their own private scope.
Not sure when it disappeared, but it wasn't supposed to.
The new one will be better:
should work the same way they do in match patterns
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.