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

2017-07-08 Thread Alasdair McAndrew
Thanks everybody - you've given me a lot of good ideas.  As to the Lindenmayer 
package, I did know of it.  And I am in fact exploring Lindenmayer systems from 
a very fundamental perspective, which is why I don't want to use a pre-made 
library or package, but write bits and pieces as I go.  Thanks again.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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")
>  ("C" . "CCA"))
>s
> 
> (module+ test
>(require rackunit)
>(check-equal? (foo "") "")
>(check-equal? (foo "ABCABC")   "ACBACCAACBACCA")
>(check-equal? (foo "ABCDABCD") "ACBACCADACBACCAD"))
> 
> 
> It's not necessarily the most maintainable (note the duplicated info 
> between the regexp and the map) nor most efficient, but it's OK, IMHO.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[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 Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Random values in Typed Racket?

2017-07-05 Thread Alasdair McAndrew
Well, after a bit of fiddling, I've discovered I can indeed do what I need to, 
with a judicious use of "let" for creating a swag of random values, and 
ensuring that their use is all within the scope of let.  So far, all good!

On Thursday, 6 July 2017 10:54:53 UTC+10, Royall Spence  wrote:
> Sounds like two questions wrapped into one. When it comes to setting
> names to values, Scheme programming encourages the use of a "let"
> expression to bind values to names inside of a (usually narrow) scope
> rather than assigning a value to a variable. See more here:
> https://docs.racket-lang.org/guide/let.html
> 
> As for the typed random value, the Flonum from (random) should be fine
> since a Flonum is also a Real. Can you provide a short example of
> runnable code that exposes the problem you're having?
> 
> On Wed, Jul 5, 2017, at 08:39 PM, Alasdair McAndrew wrote:
> > I'm doing a little programming which requires the use of some random
> > numbers.  Basically I add a random value at one stage, and subtract it a
> > bit later.  Something like this pseudo-code (where "x" is an existing
> > variable):
> > 
> >set rand_value <- (random)
> >set new_value <- x + rand_value
> > 
> >... do stuff ...
> > 
> >set new_value <- new_value  - rand_value
> > 
> > All values may be considered Reals.  I tried to do this in Typed Racket,
> > where x was of type "Real" and got errors about mismatched types:
> > "(random)" produces a "flonum".  I was also using "set!" for the
> > assignment of the random value, which I understand to be poor practice:
> > how would I do something like the above in a more "rackety" manner? 
> > Thank you!
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Drracket crashing on startup

2017-07-05 Thread Alasdair McAndrew
This morning, when I attempted to start Drracket from a terminal (I'm using 
Archlinux, 64 bit, with the most recently upgraded versions of Racket and 
Drracket), I obtained this error:

SIGSEGV MAPERR si_code 1 fault on addr 0xe8042caa
[2]26140 abort (core dumped)  drracket

A bit of web searching reveals that this error is not unknown, but I can't find 
the solution.  What I believe I can do is to log out and back in again, but 
that's a pain.

Does anybody here know how I can overcome this error other than restarting my 
login session?  Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Random values in Typed Racket?

2017-07-05 Thread Alasdair McAndrew
I'm doing a little programming which requires the use of some random numbers.  
Basically I add a random value at one stage, and subtract it a bit later.  
Something like this pseudo-code (where "x" is an existing variable):

   set rand_value <- (random)
   set new_value <- x + rand_value

   ... do stuff ...

   set new_value <- new_value  - rand_value

All values may be considered Reals.  I tried to do this in Typed Racket, where 
x was of type "Real" and got errors about mismatched types: "(random)" produces 
a "flonum".  I was also using "set!" for the assignment of the random value, 
which I understand to be poor practice: how would I do something like the above 
in a more "rackety" manner?  Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Scientific libraries?

2017-06-02 Thread Alasdair McAndrew
On Friday, June 2, 2017 at 3:24:12 PM UTC+10, Konrad Hinsen wrote:
> On 02/06/17 02:50, Alasdair McAndrew wrote:
> 
> > I have been experimenting with the bigfloat library, which I understand to 
> > be a wrapper for the GNU MPFR library.  And it works well.  But I'm 
> > wondering if anybody's given thought about porting other scientific 
> > libraries, such as GNU GSL to Racket.  Is this the sort of thing which 
> > would be very difficult indeed - or are there tools available to do the 
> > heavy lifting, so to speak, as well as much of the coding drudgery?  I 
> > would certainly like to have access to GSL.
> 
> Racket's foreign-function interface is pretty good:
> 
>http://docs.racket-lang.org/foreign/
> 
> Moreover, compared to other languages (Python etc.), you have macros to 
> abstract away much of the boilerplate that wrappers inevitably require.
> 
> The main work is (1) designing a good API on the Racket side and (2) 
> providing sufficient tests that users will trust the code. For GSL the 
> API should not be too hard because its structure is simple and it 
> doesn't rely on complex data structures.
> 
> - Konrad.

Thank you very much - that would appear to be the way to go.  I note that GSL 
has been ported to Common Lisp, using a similar approach (libffi) - see 
https://common-lisp.net/project/gsll/ so I suppose it could also be ported to 
Racket.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Scientific libraries?

2017-06-01 Thread Alasdair McAndrew
I have been experimenting with the bigfloat library, which I understand to be a 
wrapper for the GNU MPFR library.  And it works well.  But I'm wondering if 
anybody's given thought about porting other scientific libraries, such as GNU 
GSL to Racket.  Is this the sort of thing which would be very difficult indeed 
- or are there tools available to do the heavy lifting, so to speak, as well as 
much of the coding drudgery?  I would certainly like to have access to GSL.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Displaying limited decimal places of a BigFloat?

2017-05-25 Thread Alasdair McAndrew
On Thursday, 25 May 2017 23:44:58 UTC+10, David K. Storrs  wrote:
> This isn't smooth, but it works:
> 
> #lang at-exp racket
> (first (regexp-match @pregexp{\d+\.\d{0,4}} "15.123456789"))
> (first (regexp-match @pregexp{\d+\.\d{0,4}} "15.12"))
> 
Thank you - that is certainly more complicated than I though it would be.  
Another way would be to create a new real number, something like

(exact->inexact (bigfloat->real x))

and then apply the conversion to and from a string to it.  For example:

> (require math/bigfloat)
> (bf-precision 255)
> (define x (bfsqrt (bf 3)))
> x
(bf 
#e1.73205080756887729352744634150587236694280525381038062805580697945193301690881)
> (displayln (string->number (real->decimal-string (exact->inexact 
> (bigfloat->real x)) 4 )))
1.732

I was just hoping there might be something neater!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] DrRacket has become unusable: freezes almost immediately

2017-05-23 Thread Alasdair McAndrew
> After the `killall` from tty2, did the shell you started DrRacket from have 
> any output?
> 
> Thanks for helping us investigate!
> 
> Vincent

Unfortunately not.  After going to tty2, entering "killall drracket" and back 
to tty1, the terminal was as I left it, with just the command "drracket" shown 
as the previous command.  I'm happy to check logs, but I'm not sure which 
ones...

It also may be a matter of a library not behaving properly: sometimes my system 
(which runs on a laptop) doesn't wake up properly from a hibernation.  I should 
probably check with a reboot (which I'd rather avoid if possible), or a logout 
from my KDE session and a new login.

I'll do some more fiddlin'... until then it's back to Emacs and Geiser!

-Alasdair

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] DrRacket has become unusable: freezes almost immediately

2017-05-23 Thread Alasdair McAndrew
On Tuesday, 23 May 2017 21:06:17 UTC+10, Robby Findler  wrote:
> If you start DrRacket from the shell, trigger the bad behavior and then type 
> control-c in the shell, do you get any output?
> 
> 
> Robby
> 
Thanks for the suggestion - which I had in fact tried, to no avail.  DrRacket 
froze, and the only way out of it was via tty2.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] DrRacket has become unusable: freezes almost immediately

2017-05-23 Thread Alasdair McAndrew
I have had no problem running DrRacket on linux, under KDE Plasma, until now.  
But now it seems to crash constantly.  All I need to do is:

1. Open it up from the KDE menu
2. Open up the File menu

and then it freezes, and also causes a system freeze, as it appears to be using 
100% of CPU (according to "top").  The only way to recover is to open up tty2, 
and "killall drracket" and then go back to tty1, which on my system is running 
X.  

Does anybody know how to get DrRacket to run again?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Managing packages, raco and DrRacket

2017-05-20 Thread Alasdair McAndrew
I am mostly a newbie, and I am using Racket 6.9 on Linux.  I have set up the 
environment variable $PLTUSERHOME to point to a directory in which I do all my 
work.  This works well if I'm using Racket from the command line.

However, DrRacket doesn't seem to know about this, in consequence of which it 
will place installed packages under 

~/.racket/6.9/pkgs/

If I use "raco pkg install" from the command line, then packages end up in

$PLTUSERHOME/.racket/6.9/pkgs/

I can't find a preference in DrRacket which will allow me to specify multiple 
install directories, or indeed change the package directory to the second one 
above.  I'm sure all this is discussed at length in the documentation for raco 
and DrRacket.  But there's a lot of stuff here, and it's easy (for me at least) 
to get lost in it.  

How can I specify directories so that both command-line raco and DrRacket agree?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.