Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread William G Hatch
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

Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread Robby Findler
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)

Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread Matthew Butterick
> 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

Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread David Storrs
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

Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread Robby Findler
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

Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread Philip McGrath
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"]

Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread Alasdair McAndrew
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

Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread Neil Van Dyke
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")

[racket-users] Replacing multiple characters in a string?

2017-07-08 Thread Alasdair McAndrew
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