Or, arguably, not Rackety enough, until it's possible to embed one #lang within
another (submodules at least, but hey why not lambdas?)
I've been exploring this more and more. It is related to my shell
project (rash, which does allow embedding at the expression level), and
I've been thinking
Keep reading?
#lang lindenmayer racket
## axiom ##
ABCABC
## rules ##
A -> AC
B -> BA
C -> CCA
## variables ##
n=1
(provide A B C start finish)
(define (finish l vars) (writeln l))
(define (A s vars) (cons 'A s))
(define (B s vars)
> On Jul 8, 2017, at 7:15 AM, Robby Findler wrote:
>
> Below is another approach that may be too much Rackety for your taste: :)
>
> http://docs.racket-lang.org/lindenmayer/
Or, arguably, not Rackety enough, until it's possible to embed one #lang within
I'd probably do this:
(apply string-append
(for/list ((letter (string->list str)))
(cond [(equal? letter #\A) "AC"]
[(equal? letter #\B) "BA"]
[(equal? letter #\C) "CCA"])))
--
You received this message because you are subscribed to the Google Groups
Below is another approach that may be too much Rackety for your taste: :)
http://docs.racket-lang.org/lindenmayer/
Robby
#lang lindenmayer
## axiom ##
ABCABC
## rules ##
A -> AC
B -> BA
C -> CCA
## variables ##
n=1
--
You received this message because you are subscribed to the Google
This works, for instance (and I would much prefer case to hash-ref):
#lang typed/racket
(regexp-replace* #rx"[ABC]"
"ABCABC"
(λ ([c : String] . _)
(case c
[("A") "AC"]
[("B") "BA"]
Many thanks - that works fine! And it makes sense, to use regexp-replace* with
a hash table. (All these things I'm still finding out...) Is it possible to
do this - or something similar - in Typed Racket?
On Saturday, 8 July 2017 22:45:04 UTC+10, Neil Van Dyke wrote:
> This is one OK way
This is one OK way that people are likely to do:
#lang racket/base
(define (foo str)
(regexp-replace* #rx"[ABC]"
str
(lambda (s)
(hash-ref #hash(("A" . "AC")
("B" . "BA")
Suppose I have a string "ABCABC" and I want to replace all A's with "AC", all
B's with "BA" and all C's with "CCA", so that the result is
ACBACCAACBACCA
What is the canonical way of doing this in Racket?
--
You received this message because you are subscribed to the Google Groups
"Racket
9 matches
Mail list logo