Re: [Chicken-hackers] a cas of chicken overoptimizing

2012-02-14 Thread Felix
 
 (define (write-blob-to-sql sql identifier last blob c-c)
  (define ins '())
  (define del '())
  (if (vector? blob)
  (begin
   (set! ins (vector-ref blob 1))
   (set! del (vector-ref blob 2))
   (set! blob (vector-ref blob 0
  (if (or (pair? ins) (pair? del))
  (handle-ins-and-del))
  (do-some-more))
 
 handle-ins-and-del used to be reliably executed for at least a
 year.

This is caused by a flow-analysis bug. Compiling with -verbose gives
warnings about these two type-checks, so you should enable this option
if you assume something's not right.

As a quick fix, changing line 645 in scrutinizer.scm to (if #f ...)
should get your code running. I will try to provide a proper patch
in the meantime.

Thanks for reporting this.


cheers,
felix

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


Re: [Chicken-hackers] [PATH] Use hash table instead of flat list for lambda literals

2012-02-14 Thread Jörg F . Wittenberger

On Feb 13 2012, Peter Bex wrote:


On Mon, Feb 13, 2012 at 03:11:05PM -0700, Alan Post wrote:

I do think that choice is fine, yes.  Does the hash table resize
itself when it gets too many entries in it?


No, unfortunately these hash tables are pretty basic and too low-level
to do such things.


Just in case hash table turn out not to be too helpful
(and not implying that balanced trees would really help)
it might be helpful to have some alternative.

Best regards

/Jörg

(Maybe someone fluent with the egg system could turn this
into an egg anyway?)

This file should is original name aggregate-chicken.scm
http://askemos.org/A5ffdc9d14b6e2dbb899e2240ea8ea99b
It implements a hashtable API to LLRB-trees.
Two examples: a) LLRB tree indexed by symbols implemented
as a pure data structure and b) a tree indexed by strings
and updated in place with no additional allocation.
The actual implementation is done by this code
http://askemos.org/A532a4158b6424c2c2d2b8b5b08d32994
llrbtree.scm
(In comment this contains yet one more example:
and integer-index tree).

The code conditionally expands either to the use
of records (for the sake of safety and testing)
or direct ##sys#slot references (for speed).

This code is actually rather well tested. (As you might
have noted I'm running quite some network related code
constantly.  This used to spell problems with chicken's
time queue handling.  That's the code, which replaced
those linear lists in my chicken.  (Amounts to x*10^6
threads a day installing timeouts around their i/o.
The symbol and string tables are actually used to
implement variable ennvironments.)







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


[Chicken-hackers] Thrush operator

2012-02-14 Thread Moritz Heidkamp
Hello Chickeneers,

find attached a suggested addition to miscmacros: the thrush operator
family. Apparently it stems from Raymond Smullyan's book on
combinatorial logic To Mock a Mockingbird, which I haven't read
(yet). I've first learned about it through Clojure and have found it
quite nice for increasing the readability of chained calls. See Debasish
Ghosh's post [1] about it for some background.

As a practical example, consider this code:

  (write (fold + 0
   (map (lambda (i) (* 2 i)) 
(iota 10

Using the thrush operator it can be written like this:

  (- (iota 10)
   (map (lambda (i) (* 2 i)))
   (fold + 0)
   (write))

which basically expands to the expression above, i.e. it inserts each
expression as the last argument of the following expression. I find it
much easier to read though since the order of evaluation is the order of
appearance in the code. I like to think of it like `let*' as opposed to
nested `lambda':

  ((lambda (x) ((lambda (y) ((lambda (z) (+ x y z)) 3)) 2)) 1)

versus:
  
  (let* ((x 1) (y 2) (z 3)) (+ x y z))

Much easier to track what's going on there as stuff that belongs
together is visually close to each other. 

There's also `-' which inserts each expression as the first argument of
the following one. The difference:

  (- 10 (- 3)) ; = -7
  (- 10 (- 3))  ; = 7

For kicks and fun I also added starred versions (`-*' and `-*') which
are multi-value aware. Not sure how useful that is and I didn't want to
add it to the default macros to avoid the overhead. But it's good to
have them just for completeness sake!

I guess that's about it. I'm not sure if adding it to miscmacros is a
great idea, might as well just create a `thrush' egg. OTOH we have the
similar `doto' macro in there already. Comments?


Moritz

[1] http://debasishg.blogspot.com/2010/04/thrush-in-clojure.html
Index: miscmacros.scm
===
--- miscmacros.scm	(revision 25904)
+++ miscmacros.scm	(working copy)
@@ -9,13 +9,14 @@
define-optionals define-parameter define-enum
ignore-values ignore-errors
ecase
-   define-syntax-rule)
+   define-syntax-rule
+   - -* - -*)
 
   (import scheme)
   ;; No effect -- caller must import these manually.
   (import (only chicken
 when unless handle-exceptions let-optionals make-parameter
-add1 sub1))
+add1 sub1 define-for-syntax))
 
 ;;; Modify locations, T-like:
 
@@ -303,4 +304,55 @@
 clauses ...
 (else (error no valid case val
 
+(define-for-syntax (expand-thrush x weave)
+  (let loop ((y (cdr x)) (form (car x)))
+(if (null? y)
+form
+(let ((z (car y)))
+  (loop (cdr y)
+(weave z form))
+
+(define-syntax -
+  (ir-macro-transformer
+   (lambda (x i c)
+ (expand-thrush
+  (cdr x)
+  (lambda (z form)
+(cons (car z)
+  (cons form (cdr z
+
+(define-syntax -*
+  (ir-macro-transformer
+   (lambda (x i c)
+ (expand-thrush
+  (cdr x)
+  (lambda (z form)
+`(receive args ,form
+   (apply
+,(car z)
+(append args (list . ,(cdr z))
+
+(define-syntax -
+  (ir-macro-transformer 
+   (lambda (x i c)
+ (expand-thrush
+  (cdr x)
+  (lambda (z form)
+(append z (list form)))
+
+(define-syntax -*
+  (ir-macro-transformer 
+   (lambda (x i c)
+ (expand-thrush
+  (cdr x)
+  (lambda (z form)
+`(receive args ,form
+   (apply
+,(car z)
+(append (list . ,(cdr z)) args
+
 )
+
+
+
+
Index: tests/run.scm
===
--- tests/run.scm	(revision 0)
+++ tests/run.scm	(working copy)
@@ -0,0 +1,22 @@
+(use test srfi-1 miscmacros)
+
+(test 1 (- 99 (/ 11) (/ 9)))
+
+(test '(1 2 3 4)
+  (-* (values 1 2)
+   (list 3)
+   (append '(4
+
+(test 7 (- 10 (- 3)))
+(test -7 (- 10 (- 3)))
+
+(test 9 (- 1 (+ 2) (* 3)))
+
+(test 9 (- '(1 2 3)
+ (map add1)
+ (fold + 0)))
+
+(test '((foo . 100) (bar . 200))
+  (-* (values '(foo bar) '(100 200))
+(map cons)))
+
___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] Thrush operator

2012-02-14 Thread Jörg F . Wittenberger

On Feb 14 2012, Moritz Heidkamp wrote:


Hello Chickeneers,

find attached a suggested addition to miscmacros: the thrush operator
family. Apparently it stems from Raymond Smullyan's book on
combinatorial logic To Mock a Mockingbird, which I haven't read
(yet). I've first learned about it through Clojure and have found it
quite nice for increasing the readability of chained calls. See Debasish
Ghosh's post [1] about it for some background.


Hi Moritz,

May I suggest a possibly obvious extension
(Long ago I've been playing with similar notations):

I rather loved to think instead of inserting the (*single*)
value of the expression into the next expression of something
along the lines of physical wires:
connect (pass) all the result(s) of the first expression into the next
(which would then need to accept as many values as the stage
before returns.







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


Re: [Chicken-hackers] Thrush operator

2012-02-14 Thread Evan Hanson
On 02/14/12 at 10:35pm, Jörg F. Wittenberger wrote:
 I rather loved to think instead of inserting the (*single*)
 value of the expression into the next expression of something
 along the lines of physical wires:

A classic, along those lines: http://dkeenan.com/Lambda/

Cheers,

Evan

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


Re: [Chicken-hackers] Thrush operator

2012-02-14 Thread Moritz Heidkamp
Hi Jörg,

Jörg F. Wittenberger joerg.wittenber...@softeyes.net writes:
 I rather loved to think instead of inserting the (*single*)
 value of the expression into the next expression of something
 along the lines of physical wires:
 connect (pass) all the result(s) of the first expression into the next
 (which would then need to accept as many values as the stage
 before returns.

if I understand you correctly, this is exactly what the starred
versions, `-*' and `-*', do. Or did I get you wrong?

Peter had another idea worth considering: using placeholders like `cut'
and `cute' do:

  (- world
  (list hello )
  (string-intersperse  ,)
  (print  .))

As this silly example demonstrates this could be used to wire values
into arbitrary argument positions. It's a bit more flexible and it may
be clearer what's going on but also adds some line noise. I have to
think about that!


Moritz

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