Re: [Chicken-users] u8vector to numbers bignum

2015-05-29 Thread chi
> (define (bignum->u8vector/host-byte-order num)
>   (unless (bignum? num) (error "Argument is not a bignum!" num))
> 
>   (let* ((word-size (cond-expand (64bit 8) (else 4))) ; Is there a better way?
>  (bignum-contents (##sys#slot num 1))   ; Digits preceded by sign word
>  (bignum-digits (substring bignum-contents word-size)))
> (blob->u8vector/shared (string->blob bignum-digits

That's pretty fascinating. I wonder if you could even just C_copy_memory the
bignum-contents+word into an existing blob of large enough size, instead of that
substring/string->blob. Assuming you know your number is of fixed but >64 bit
size, that is. (1024 bit for instance). If you didn't want native order, instead
of C_copy_memory you could do a word based converter to network byte order
called I dunno, C_copy_flipwords.

Incidentally, chicken.h defines C_WORD_SIZE, and I think it's a fairly safe
assumption even though the core never explicitly exports that value into scheme.
You could probably do this pretty confidently:

(define word-octets (/ (foreign-value "C_WORD_SIZE" integer) 8)

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-29 Thread John Cowan
Jinsong Liang scripsit:

> I want to learn some basic macro programming in Chicken. However, it seems
> there are multiple macro definition APIs in Chicken: define-syntax,
> syntax-rules, syntax-case, define-macro. Which one should I start with?

Define-macro is completely obsolete and not supported in Chicken 4 or
any modern Scheme.

Define-syntax is a general wrapper for defining macros like this:

(define-syntax  ( ))

This defines a macro named  using the syntax transformer
.  The syntax and semantics of  depend on the
symbol used for .

Define-syntax corresponds to define and can be written in the same
places.  You can also define local macros (like local variables) by
using let-syntax or let-syntax*, which correspond to let and let*.

Chicken supports three syntax transformers:  syntax-rules,
er-macro-transformer, and ir-macro-transformer.  The abbreviations "er"
and "ir" stand for "explicit renaming" and "implicit renaming".  It does
not support syntax-case, sc-macro-transformer ("syntactic closure"),
or rsc-macro-transformer ("reverse syntactic closure"), though they are
supported by other Schemes.

Syntax-rules is the most widely supported, the easiest to use, and
the most idiot-proof, though not the most powerful.  The other syntax
transformers are more powerful but also more dangerous.

> Also, I have heard that, different from Lisp, macro programming in Scheme
> is not recommended. Is it true?

Procedures provide new run-time function, whereas macros provide new
syntax forms to extend the basic set (if, cond, set!, lambda, etc.)
They serve different roles.

But in general, you should write a procedure if you can.  If not, use a
syntax-rules macro.  Only if a syntax-rules macro is insufficient should
you use an implicit-renaming macro, and only if that is too slow should
you use an explicit-renaming macro.

Googling for "syntax-rules" will point you to a lot of basic tutorials.
When you want something more advanced, look for "JRM's Syntax-rules
Primer for the Mildly Eccentric".  Read that until you have trouble
understanding it; you now know as much as you can absorb.  Go back to
it later when you need more.

-- 
John Cowan  http://www.ccil.org/~cowanco...@ccil.org
Half the lies they tell about me are true.
--Tallulah Bankhead, American actress

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-29 Thread Matt Gushee
Hi, Jinsong--

On Fri, May 29, 2015 at 6:25 PM, Jinsong Liang 
wrote:

>
> I want to learn some basic macro programming in Chicken. However, it seems
> there are multiple macro definition APIs in Chicken: define-syntax,
> syntax-rules, syntax-case, define-macro. Which one should I start with?
>

It can indeed be a bit confusing, and my knowledge is not very advanced,
but here's what I know:

  * define-macro is old. I'm not sure it is even still supported in Chicken
4.x, but
 it's certainly not recommended.

  * define-syntax is currently the primary macro form, and you use it
together with syntax-rules. E.g.:

(define-syntax NAME
(syntax-rules ()
(PATTERN BODY)  ))

   * I've never used syntax-case - which is not to say that you shouldn't,
but I'm pretty sure it is not considered "basic."

If the Chicken documents don't give you enough information, I've found Kent
Dybvig's book _The Scheme Programming Language_ helpful in learning
syntax-rules. It's available online at:

http://www.scheme.com/tspl3/

You want Chapter 3 and maybe also Chapter 8. There is now a 4th edition of
the book, but it covers R6RS Scheme; I think the 3rd edition is more
applicable to Chicken.


> Also, I have heard that, different from Lisp, macro programming in Scheme
> is not recommended. Is it true?
>

I wouldn't put it that way, but what I have always heard is that you
shouldn't use a macro when a procedure will work.

HTH.

--
Matt Gushee
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] Scheduled call-cc.org server maintenance

2015-05-29 Thread Mario Domenech Goulart
Hi,

The call-cc.org server will undergo scheduled maintenance on, May
30th, at 07:00h EST.  The expected maintenance duration is 3
hours.

During the maintenance time, the services provided by the following
subdomains will be unavailable:

* bugs.call-cc.org
* code.call-cc.org
* gazette.call-c.org
* paste.call-cc.org
* tests.call-cc.org
* wiki.call-cc.org
* www.call-cc.org

The following subdomains will still be available:

* api.call-cc.org
* salmonella-freebsd-x86-64.call-cc.org
* salmonella-linux-x86.call-cc.org
* salmonella-linux-x86-64.call-cc.org

The salmonella machines will be available, but may be affected because
they use some services provided by the servers that will be shut down
during the maintenance time.

Note that the canonical eggs server (chicken.kitten-technologies.co.uk)
will NOT be affected.

We apologize in advance for the inconvenience.

Best wishes,
Mario (on behalf of the CHICKEN Team)
--
http://parenteses.org/mario

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-29 Thread Jinsong Liang
Thank you for more examples!

I want to learn some basic macro programming in Chicken. However, it seems
there are multiple macro definition APIs in Chicken: define-syntax,
syntax-rules, syntax-case, define-macro. Which one should I start with?

Also, I have heard that, different from Lisp, macro programming in Scheme
is not recommended. Is it true?

Thank you!

Jinsong

On Fri, May 29, 2015 at 7:44 PM, Michele La Monaca <
mikele.chic...@lamonaca.net> wrote:

> On Fri, May 29, 2015 at 3:10 AM, Jinsong Liang 
> wrote:
> > Thank you Michele! This is a nice example.
>
> Nice but maybe not very useful:
>
> (apply-syntax or (#f (+ 1 2) (print "hello")))
>
> is just a longer and more cumbersome version of
>
> (or (#f (+ 1 2) (print "hello")))
>
> A far more valuable macro is the following:
>
> (define-macro apply-any
>   (lambda (_ lst)
> (eval `(cons ',_ ,lst
>
> (define l '(#f (+ 1 2) (print "hello")))
> (apply-any or l)
>
> => 3
>
> (let ((x 9)) (apply-any or '(#f (+ x 1) (print "hello"
>
> => 10
>
> (apply-any + (list 1 2 3))
>
> => 6
>
> Regards,
> Michele
>
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Mutual recursion w/ comparse

2015-05-29 Thread Matt Gushee
Hi, Moritz--

On Fri, May 29, 2015 at 3:00 AM, Moritz Heidkamp  wrote:


> > I also saw that comparse provides a similar macro called
> > 'recursive-parser', but for some reason that didn't work when I tried it.
> > Maybe I was using it wrong.
>
> That's right -- it's slightly more efficient than your version as it
> memoizes the wrapped parser so that it only needs to be constructed the
> first time it is used.
>
> If you are on Comparse 0.2.2 you would define your parser just like
> before, wrapped in `recursive-parser', i.e. the interface should be
> identical to your `mrp'. The interface used to be different before
> Comparse 0.2.2.


That was the problem. It turned out I had 0.1.0 installed on this machine.
I updated comparse, and all is well! Thank you.

Matt
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-29 Thread Michele La Monaca
On Fri, May 29, 2015 at 3:10 AM, Jinsong Liang  wrote:
> Thank you Michele! This is a nice example.

Nice but maybe not very useful:

(apply-syntax or (#f (+ 1 2) (print "hello")))

is just a longer and more cumbersome version of

(or (#f (+ 1 2) (print "hello")))

A far more valuable macro is the following:

(define-macro apply-any
  (lambda (_ lst)
(eval `(cons ',_ ,lst

(define l '(#f (+ 1 2) (print "hello")))
(apply-any or l)

=> 3

(let ((x 9)) (apply-any or '(#f (+ x 1) (print "hello"

=> 10

(apply-any + (list 1 2 3))

=> 6

Regards,
Michele

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] u8vector to numbers bignum

2015-05-29 Thread Stephen Eilert
On Thu, May 28, 2015 at 9:09 PM, John Cowan  wrote:

> Peter Bex scripsit:
>
> > If this is such an important feature it may make more sense to include
> > a "proper" PRNG.
>
> Different applications will want fast crude random-ish numbers, PRNGs,
> cryptographic PRNGs, or full quantum randomness, with tradeoffs for
> speed and quality.  Since that's so, I'd rather require programmers
> to make the choice up front rather than fall back on some dubious
> OS version that does who-knows-what.
>
>
Not all applications require cryptographically secure real random number
generators. In fact, I'd argue that most random usage is not for that sort
of thing. It will be used in tutorials, or in games for a purpose such as
selecting between several available sounds. Or procedural generation if it
doesn't totally suck.

If you *are* writing something that really requires a better quality
pseudorandom generator, odds are that you will have to import one anyway.

I have no idea of what rand() uses internally, and much less what is
Chicken is actually calling on Win32. So one thing that could be of value
is not relying on the OS implementation and instead providing our own
(Mersenne Twister?). This would remove a core dependency and guarantee
consistency when running on all operating systems. Even if it is
consistently crappy(which MT doesn't appear to be, even if it should not be
used for crypto). That would be preferable, so you'd deal with it in the
beginning, instead of when porting to another OS, when you've already
forgotten all about the random generator.

For reference:
(random N)  procedure

Returns a pseudo-random integer in [0, N-1]. N is an integer.

On Windows, N and the random value are exact integer.

*Warning*: This procedure uses *rand(3)* internally and exhibits its
deficiencies, including low quality pseudo-randomness:

   - On Windows and Solaris, only 32768 unique random values can be
   generated in the range [0, N-1]. If N >= 32768, there will be gaps in
   the result set.
   - On Mac OS X, Windows and some other platforms, little variance in
   output is seen with nearby seeds. Since the random generator is seeded with
   current-seconds at startup, new processes may see similar or identical
   random sequences for up to a minute.
   - On Linux, *rand(3)* is an alias to *random(3)*, which provides output
   of reasonable quality.


— Stephen
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] u8vector to numbers bignum

2015-05-29 Thread cowan
chi scripsit:

> Ironically, that is exactly what the SRFI-27 module implements.
> http://wiki.call-cc.org/eggref/4/srfi-27#random-sources
> Could make an insecure random source, or even a totally non-random random
> source I imagine.

I had no idea it was so comprehensively extended.

-- 
John Cowan  http://www.ccil.org/~cowanco...@ccil.org
If you have ever wondered if you are in hell, it has been said, then
you are on a well-traveled road of spiritual inquiry.  If you are
absolutely sure you are in hell, however, then you must be on the Cross
Bronx Expressway.  --Alan Feuer, New York Times, 2002-09-20



___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Mutual recursion w/ comparse

2015-05-29 Thread Moritz Heidkamp
Hi Matt,

On 29 May 2015 02:24 CEST, Matt Gushee wrote:

> Actually, this is just a copy of the 'vac' macro from json-abnf; I changed
> the name because I had no idea what 'vac' means - whereas 'mrp' stands for
> 'mutually recursive parser'.

just a nit-pick: You also need this kind of thing for self recursive
definitions, not just mutually recursive ones.


> I also saw that comparse provides a similar macro called
> 'recursive-parser', but for some reason that didn't work when I tried it.
> Maybe I was using it wrong.

That's right -- it's slightly more efficient than your version as it
memoizes the wrapped parser so that it only needs to be constructed the
first time it is used.

If you are on Comparse 0.2.2 you would define your parser just like
before, wrapped in `recursive-parser', i.e. the interface should be
identical to your `mrp'. The interface used to be different before
Comparse 0.2.2. Note that this is still an experimental API which is why
it isn't in the documentation, yet. I think the current version will
make it, though. Let me know if it works!

Cheers
Moritz


signature.asc
Description: PGP signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users