Safe pattern matching

2013-02-09 Thread Nikita Karetnikov
Any Haskellers here? How would you rewrite the following function in Guile? foo :: [Int] -> String -> [Int] foo (x:y:ys) "+" = (x + y):ys foo (x:y:ys) "-" = (x - y):ys foo xs num = read num:xs *Main> foo [] "42" [42] *Main> foo [1,2] "42" [42,1,2] *Main> foo [1,2] "+" [3] *Main> foo [1..10

Re: Safe pattern matching

2013-02-09 Thread Daniel Hartwig
On 9 February 2013 17:57, Nikita Karetnikov wrote: > Any Haskellers here? > > How would you rewrite the following function in Guile? > > foo :: [Int] -> String -> [Int] > foo (x:y:ys) "+" = (x + y):ys > foo (x:y:ys) "-" = (x - y):ys > foo xs num = read num:xs Indeed, match can do this. The

Re: Safe pattern matching

2013-02-09 Thread Daniel Hartwig
On 9 February 2013 18:12, Daniel Hartwig wrote: > Using symbols and literals, rather than strings: Though strings work just as well as symbols :-)

Re: Safe pattern matching

2013-02-09 Thread Ian Price
Nikita Karetnikov writes: > How would you rewrite the following function in Guile? > > foo :: [Int] -> String -> [Int] > foo (x:y:ys) "+" = (x + y):ys > foo (x:y:ys) "-" = (x - y):ys > foo xs num = read num:xs Daniel covered most of this already, but instead you might consider (define foo

Re: Safe pattern matching

2013-02-09 Thread Ian Price
> the nearest analogue to read is object->string, but it is not a generic. That should be string->object. It's funny how often I mix up a->b and b->a -- Ian Price -- shift-reset.com "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy

Re: statically linking in srfi modules

2013-02-09 Thread Richard Shann
Well it seems I may have been premature in saying that srfi-1 was successfully loaded. Although the error message is gone, there is no symbol 'map which srfi-1 should have re-defined. Can someone suggest what this might be a symptom of? Denemo has a command line interpreter for guile, so I can fe

Re: statically linking in srfi modules

2013-02-09 Thread Mark H Weaver
Richard Shann writes: > Well it seems I may have been premature in saying that srfi-1 was > successfully loaded. Although the error message is gone, there is no > symbol 'map which srfi-1 should have re-defined. > Can someone suggest what this might be a symptom of? I know what's wrong. Please

Re: statically linking in srfi modules

2013-02-09 Thread Mark H Weaver
Richard Shann writes: > Well it seems I may have been premature in saying that srfi-1 was > successfully loaded. Although the error message is gone, there is no > symbol 'map which srfi-1 should have re-defined. > Can someone suggest what this might be a symptom of? I wrote: > I know what's wro

Re: Guile not running properly on GNU/Hurd

2013-02-09 Thread Neal H. Walfield
At Sat, 2 Feb 2013 23:24:38 +0100, Richard Braun wrote: > On Sat, Feb 02, 2013 at 07:51:38PM +0100, Gabriel Schnoering wrote: > > I can't run guile in gdb as there are some error with the garbage > > collector. > > These are probably not errors. Many language interpretors rely on > receiving SIGSE

Re: statically linking in srfi modules

2013-02-09 Thread Richard Shann
On Sat, 2013-02-09 at 10:32 -0500, Mark H Weaver wrote: > Richard Shann writes: > > Well it seems I may have been premature in saying that srfi-1 was > > successfully loaded. Although the error message is gone, there is no > > symbol 'map which srfi-1 should have re-defined. > > Can someone sugge

Re: statically linking in srfi modules

2013-02-09 Thread Richard Shann
More on that call to scm_c_call_with_current_module (scm_c_resolve_module ("srfi srfi-1"), init_srfi_1, NULL); I have had a look using gdb and it is exiting during the call to scm_c_resolve_module() HTH Richard

Re: statically linking in srfi modules

2013-02-09 Thread Mark H Weaver
Hi Richard, Don't worry, we'll get it working. Here's another attempt. Replace the calls to 'scm_c_register_extension' with the following: scm_c_call_with_current_module (scm_c_resolve_module ("guile"), bind_srfi_initializers, NULL); With the following additi