Re: "AIscm" array JIT

2016-06-11 Thread Jan Wedekind
On 10. Juni 2016 22:48:56 GMT+01:00, Arne Babenhauserheide  
wrote:
>Hi Jan,
>
>Jan Wedekind writes:
>
>> Yes, here are some examples with empty arrays and arrays with 250,000
>
>> elements. I hope that the upcoming Guile version 2.2 will help
>increase 
>> performance as well.
>>
>>  $ make bench
>>  Making bench in bench
>>  make[1]: Entering directory '/home/jan/test/aiscm/bench'
>>  LD_LIBRARY_PATH=./.libs:/usr/local/lib GC_INITIAL_HEAP_SIZE=1G
>GC_USE_ENTIRE_HEAP=Y /usr/bin/guile bench.scm
>> user system 
>totalreal
>>  Guile GOOPS method dispatch0.40   0.00  
>0.40 (  0.40)
>>  Guile make empty sequence  0.000150   0.00  
>0.000150 (  0.000140)
>>  Guile allocate memory  0.000190   0.00  
>0.000190 (  0.000200)
>>  Guile negate empty sequence0.001580   0.000110  
>0.001690 (  0.001690)
>>  Guile make sequence0.000230   0.10  
>0.000240 (  0.000240)
>>  Guile negate sequence  0.002400   0.000930  
>0.003330 (  0.003350)
>>  C allocate memory  0.60   0.00  
>0.60 (  0.60)
>>  C negate empty sequence0.30   0.00  
>0.30 (  0.30)
>>  C negate sequence  0.000730   0.00  
>0.000730 (  0.000720)
>>  make[1]: Leaving directory '/home/jan/test/aiscm/bench'
>
>Do you have a comparison to the same tasks without compilation?
>
>Best wishes,
>Arne

Hi Arne,
The benchmark does not include compilation times.

Regards
Jan
-- 
Jan Wedekind
http://www.wedesoft.de/



Re: "AIscm" array JIT

2016-06-11 Thread Jan Wedekind
On 11. Juni 2016 02:42:19 GMT+01:00, Basa Centro  wrote:
>I've had the AIscm code on my laptop for months, I was looking at how
>to do something with GOOPS.  Nice work, and I hope you continue on it.
>Another "me too".

Yes, one can use GOOPS objects without mutating. Unlike Clojure, Scheme does 
not enforce immutability but one can decide to not use the mutating features 
anyway.
-- 
Jan Wedekind
http://www.wedesoft.de/



Re: Transient environment with standard functions

2016-06-11 Thread Basa Centro
It seems in essence you are building up a Scheme expression using the
graph and the code snippets and evaluating that expression.  If this
is the case, do you even need to use a module system and/or to
explicitly create environments?  Prima facie, it looks like you are
trying to reinvent the wheel.  Is your graph really just equivalent to
an S-exp?

Scheme is lexically scoped, and creates a "transient environment" for
you through the use of lambdas.

Your use of thunks suggests that you are doing caching or lazy-eval.

I'm not sure this helps, but I hope so.  When thinking about this
topic, I had this mental image of a GUI for building Scheme
expressions--like "Visual Scheme". :)

(Basa)

On 6/10/16, Matthew Keeter  wrote:
> The specific use case is for dataflow graphs, where you’re evaluating a
> bunch of small
> snippets of code that can refer to each other by name.
>
> I’d like to make an environment in which the variables in the same subgraph
> are
> exposed as no-argument thunks.
>
> For example, let’s say I have one subgraph that contains
> a = “12” => evaluates to 12
> b = “(+ 1 (a))” => evaluates to 13, since the (a) thunk evaluates to 12
>
> and another subgraph which contains
> x = “1” => evaluates to 1
> y = “(* (x) 2)” => evaluates to 2
>
> If I insert the thunks into (scheme-report-environment 5), they leak from
> one graph
> to another – and to be fair, the docs to say that assigning into this
> environment is
> undefined behavior.
>
> However, if I make an empty environment with (null-environment), it doesn’t
> have
> useful functions like + and *; looks like (make-module) has the same issue.
>
> I'm sure that this is possible in Guile, but I got tired of reading through
> the source
> files to hunt down undocumented function that do what I need [1].
>
> -Matt
>
> [1] Another recent incident: How do you programmatically list all of the
> variables in a module?
> You search the web, find http://www.draketo.de/proj/guile-basics/#sec-3-2,
> see a a reference to
> module-map, which doesn’t exist in the documentation, dig it up in the
> source to see its
> arguments, etc…
>
> On Jun 10, 2016, at 6:11 PM, Basa Centro  wrote:
>
>>> First of all: is the "sandboxing" aspect of these environment important?
>>
>> Taylan,
>>
>> Thanks, that's exactly what I meant by "motivation" in my first reply.
>> (There was a recent, 6 months ago or so, thread on sandboxing in
>> guile-user by the way.)
>>
>> Was Matt trying to prevent _access_ (inaccessible vs. read-only vs.
>> read/write) to data?  Or was he trying to prevent only _visibility_
>> (e.g. for hygeine)?
>>
>> I think we need to know more about "what" and "why" to answer his
>> question, rather than just "how"--if that makes any sense.  Does
>> Racket [1] even _really_ achieve what he needs to do (_prevent_ access
>> for example)?  We don't even know if we don't understand the
>> higher-level purpose.
>>
>> (Basa)
>>
>> [1] Disclaimer: I like Racket too--it is a great project.  I just hate
>> to see someone leave Guile because of a minor technicality.
>
>



Re: anyone define port types?

2016-06-11 Thread Andy Wingo
On Wed 06 Apr 2016 01:55, Matt Wette  writes:

>> On Apr 5, 2016, at 7:06 AM, Mark H Weaver  wrote:
>> 
>> Matt Wette  writes:
>> 
 On Mar 28, 2016, at 12:04 PM, Andy Wingo  wrote:
 I am working on improving our port implementation to take advantage of
 the opportunity to break ABI in 2.2.  I am wondering how much I can
 break C API as well -- there are some changes that would allow better
 user-space threading
>>> 
>>> I made an attempt to use soft ports, but backed out after I could not
>>> figure a way to extra data I wanted to associate with my port.
>>> 
>>> Addition of an access function to user-defined data would enlarge the
>>> cases for which soft ports could be used.
>> 
>> Object properties can be used to associate extra information with any
>> object that has identity, which includes ports.  See
>> 'make-object-property' in the Guile manual.
>
> Thanks.  I had forgotten about that. — Matt

I think for soft ports (and custom binary i/o ports) the idea is
actually that the "handler" procedures are actually closures.  I.e.

  (let ((my-obj ...))
(make-soft-port (vector (lambda (c) (do-write my-obj c)) ...) modes))

No need for extra arguments if you have closures.

Andy



Re: anyone define port types?

2016-06-11 Thread Andy Wingo
On Wed 30 Mar 2016 08:29, Panicz Maciej Godek  writes:

> Hi Andy,
> I have been using soft ports to implement a text widget in my GUI
> framework. I also used GOOPS, which I regret to this day, and so the
> whole framework needs a serious rewrite, but if you're collecting
> various species to the museum of make-soft-port, you can have a look:
>
> https://bitbucket.org/panicz/slayer/src/8b741c21b7372c24874d7cd1875e2aae3fc43abe/guile-modules/widgets/text-area.scm?at=default&fileviewer=file-view-default

Thanks.  The interface to soft ports hasn't changed FWIW; nothing has
changed from a Scheme programmer's perspective, except that all ports
can have buffering now.  See:

  http://www.gnu.org/software/guile/docs/master/guile.html/Buffering.html

Cheers,

Andy



Re: anyone define port types?

2016-06-11 Thread Andy Wingo
On Fri 01 Apr 2016 16:38, l...@gnu.org (Ludovic Courtès) writes:

> Here’s a port type!  :-)
>
>   https://gitlab.com/gnutls/gnutls/blob/master/guile/src/core.c#L785

Thanks!

So port types written in C will have to change unfortunately :/  From
NEWS:

** Complete overhaul of port internals

Guile's ports have been completely overhauled to allow Guile developers
and eventually Guile users to write low-level input and output routines
in Scheme.  The new internals will eventually allow for user-space
tasklets or green threads that suspend to a scheduler when they would
cause blocking I/O, allowing users to write straightforward network
services that parse their input and send their output as if it were
blocking, while under the hood Guile can multiplex many active
connections at once.

At the same time, this change makes Guile's ports implementation much
more maintainable, rationalizing the many legacy port internals and
making sure that the abstractions between the user, Guile's core ports
facility, and the port implementations result in a system that is as
performant and expressive as possible.

The interface to the user has no significant change, neither on the C
side nor on the Scheme side.  However this refactoring has changed the
interface to the port implementor in an incompatible way.  See below for
full details.

And later:

** API to define new port types from C has changed

See the newly expanded "I/O Extensions" in the manual, for full details.
Notably:

*** Remove `scm_set_port_mark'

Port mark functions have not been called since the switch to the BDW
garbage collector.

*** Remove `scm_set_port_equalp'

Likewise port equal functions weren't being called.  Given that ports
have their own internal buffers, it doesn't make sense to hook them into
equal? anyway.

*** Remove `scm_set_port_free'

It used to be that if an open port became unreachable, a special "free"
function would be called instead of the "close" function.  Now that the
BDW-GC collector allows us to run arbitrary code in finalizers, we can
simplify to just call "close" on the port and remove the separate free
functions.  Note that hooking into the garbage collector has some
overhead.  For that reason Guile exposes a new interface,
`scm_set_port_needs_close_on_gc', allowing port implementations to
indicate to Guile whether they need closing on GC or not.

*** Remove `scm_set_port_end_input', `scm_set_port_flush'

As buffering is handled by Guile itself, these functions which were to
manage an implementation-side buffer are no longer needed.

*** Change prototype of `scm_make_port_type'

The `read' (renamed from `fill_input') and `write' functions now operate
on bytevectors.  Also the `mode_bits' argument now inplicitly includes
SCM_OPN, so you don't need to include these.

*** Change prototype of port `close' function

The port close function now returns void.

*** Port and port type data structures are now opaque

Port type implementations should now use API to access port state.
However, since the change to handle port buffering centrally, port type
implementations rarely need to access unrelated port state.

*** Port types are now `scm_t_port_type*', not a tc16 value

`scm_make_port_type' now returns an opaque pointer, not a tc16.
Relatedly, the limitation that there only be 256 port types has been
lifted.

Now.  How to adapt?  You can do the #if thing with versions.  Or, maybe
we should flesh out the custom binary input/output port support so that
you can implement a GnuTLS port in Scheme.  WDYT?

Andy



Re: anyone define port types?

2016-06-11 Thread Andy Wingo
On Thu 14 Apr 2016 16:08, l...@gnu.org (Ludovic Courtès) writes:

> Andy Wingo  skribis:
>
>> I am working on improving our port implementation to take advantage of
>> the opportunity to break ABI in 2.2.  I am wondering how much I can
>> break C API as well -- there are some changes that would allow better
>> user-space threading
>> (e.g. http://thread.gmane.org/gmane.lisp.guile.devel/14158/focus=15463
>> or Chris Webber's 8sync).  But those changes would require some
>> incompatible changes to the C API related to port internals.  This API
>> is pretty much only used when implementing port types.  So, I would like
>> to collect a list of people that implement their own ports :) I know
>> Guile-GNOME does it for GNOME-VFS, though GNOME-VFS is super-old at this
>> point...  Anyway.  Looking forward to your links :)
>
> What do you conclude from this poll?  :-)
>
> From what you’ve seen, how do you think current uses would impact the
> refactoring work (and vice versa)?

Sorry for the late response :)

My conclusion is that we should not change anything about the Scheme
interface, but that with close communication with C port hackers, we can
feel OK about changing the C interface to make it both more simple and
more expressive.  Since libguile is parallel-installable and you have to
select the version of your Guile when you build your project, of course
people will be able to update / upgrade when they choose to.

I put in a lot of effort to the documentation; check it out:

  http://www.gnu.org/software/guile/docs/master/guile.html/Input-and-Output.html

Andy



Re: Transient environment with standard functions

2016-06-11 Thread Matthew Keeter
Yes, the graph is equivalent to an s-expr (with subgraphs being nested scopes).

The reason that I’m not just representing the graph as a single expression is 
for
efficiency – I’m doing incremental updates and change tracking, so you can 
update
one of the node's expressions and have the changes propagate through the graph
with a minimum number of re-evaluations.

A similar Python engine is documented here:
http://www.mattkeeter.com/projects/graph/

Regards,
Matt

On Jun 11, 2016, at 11:15 AM, Basa Centro  wrote:

> It seems in essence you are building up a Scheme expression using the
> graph and the code snippets and evaluating that expression.  If this
> is the case, do you even need to use a module system and/or to
> explicitly create environments?  Prima facie, it looks like you are
> trying to reinvent the wheel.  Is your graph really just equivalent to
> an S-exp?
> 
> Scheme is lexically scoped, and creates a "transient environment" for
> you through the use of lambdas.
> 
> Your use of thunks suggests that you are doing caching or lazy-eval.
> 
> I'm not sure this helps, but I hope so.  When thinking about this
> topic, I had this mental image of a GUI for building Scheme
> expressions--like "Visual Scheme". :)
> 
> (Basa)
> 
> On 6/10/16, Matthew Keeter  wrote:
>> The specific use case is for dataflow graphs, where you’re evaluating a
>> bunch of small
>> snippets of code that can refer to each other by name.
>> 
>> I’d like to make an environment in which the variables in the same subgraph
>> are
>> exposed as no-argument thunks.
>> 
>> For example, let’s say I have one subgraph that contains
>>a = “12” => evaluates to 12
>>b = “(+ 1 (a))” => evaluates to 13, since the (a) thunk evaluates to 12
>> 
>> and another subgraph which contains
>>x = “1” => evaluates to 1
>>y = “(* (x) 2)” => evaluates to 2
>> 
>> If I insert the thunks into (scheme-report-environment 5), they leak from
>> one graph
>> to another – and to be fair, the docs to say that assigning into this
>> environment is
>> undefined behavior.
>> 
>> However, if I make an empty environment with (null-environment), it doesn’t
>> have
>> useful functions like + and *; looks like (make-module) has the same issue.
>> 
>> I'm sure that this is possible in Guile, but I got tired of reading through
>> the source
>> files to hunt down undocumented function that do what I need [1].
>> 
>> -Matt
>> 
>> [1] Another recent incident: How do you programmatically list all of the
>> variables in a module?
>> You search the web, find http://www.draketo.de/proj/guile-basics/#sec-3-2,
>> see a a reference to
>> module-map, which doesn’t exist in the documentation, dig it up in the
>> source to see its
>> arguments, etc…
>> 
>> On Jun 10, 2016, at 6:11 PM, Basa Centro  wrote:
>> 
 First of all: is the "sandboxing" aspect of these environment important?
>>> 
>>> Taylan,
>>> 
>>> Thanks, that's exactly what I meant by "motivation" in my first reply.
>>> (There was a recent, 6 months ago or so, thread on sandboxing in
>>> guile-user by the way.)
>>> 
>>> Was Matt trying to prevent _access_ (inaccessible vs. read-only vs.
>>> read/write) to data?  Or was he trying to prevent only _visibility_
>>> (e.g. for hygeine)?
>>> 
>>> I think we need to know more about "what" and "why" to answer his
>>> question, rather than just "how"--if that makes any sense.  Does
>>> Racket [1] even _really_ achieve what he needs to do (_prevent_ access
>>> for example)?  We don't even know if we don't understand the
>>> higher-level purpose.
>>> 
>>> (Basa)
>>> 
>>> [1] Disclaimer: I like Racket too--it is a great project.  I just hate
>>> to see someone leave Guile because of a minor technicality.
>> 
>> 



Re: Transient environment with standard functions

2016-06-11 Thread Basa Centro

Yes, the graph is equivalent to an s-expr (with subgraphs being nested scopes).

The reason that I’m not just representing the graph as a single expression is
for
efficiency – I’m doing incremental updates and change tracking, so you can
update
one of the node's expressions and have the changes propagate through the graph
with a minimum number of re-evaluations.

A similar Python engine is documented here:
http://www.mattkeeter.com/projects/graph/

Matt [and List],

Sorry if your reply bounced, I was having email issues today. :(

Wow, I think I finally comprehend what you are doing.  I seem to 
remember looking at the code for a 3D scene graph in Scheme--where 
escapes me right now.  I think they used Scheme "promises" to cache 
values, again a lambda technique.


In any event, if you are translating from Python, I would encourage you 
to rethink what you are doing in light of Scheme's facilities.  A 
constraint solver might be straight-forward, as well.  Scheme is really 
good at what you are trying to do, built-in.


[
And if anyone else has ideas on this topic of optimizing the update of 
an S-exp as Matt has explained--I would be interested too.  It would be 
awesome to have something like Matt's Antimony done in Guile, trust me:


http://www.mattkeeter.com/projects/antimony/3/
]

Have fun,

(Basa)



Re: Transient environment with standard functions

2016-06-11 Thread Basa Centro
I did think of one project that uses a Lisp (CL) to let you do CAD in an 
Emacs REPL, rather than a GUI, which is Gendl:


Demo:
https://www.youtube.com/watch?v=yTcxNaBKTOc

Repo:
https://gitlab.common-lisp.net/gendl/gendl

If you haven't seen it, it uses a declarative syntax to avoid some of 
the sandboxing issues needed for public model "commons", and I think it 
does have a constraint solver to do something similar to your graph.  It 
has web based tool to display models in X3DOM/WebGL.   It doesn't get 
enough attention, IMO.  Again it is something I wish we had in Guile or 
at least Scheme.


I myself have contemplated using an implicit modeling backend with 
Sussman et al's. propagator concept to do the constraint solving, but 
that is a ways off I am afraid.


(Basa)