fibers usage

2018-12-10 Thread Catonano
I'm trying to create a server with Fibers

I copied the ping sever provided as an example in Fibers

I changed it a bit and I tried to run it

it doesn't  work

I run the server, I call it from the REPL

I send a request to the server, the I read the reply

I mean that I repeatedly call "read-line" on the socket connected to the
server

After a few times, In the middle of the reply, the prompt doesn't come back
anymore

But then, when I stop the server with ctrl-c, on the client the whole
missing line comes out suddenly

Here's a picture (the server in the upper pane, note the "^C" string and
the client in the lower pane)
https://imgur.com/a/1Qt2b4o

I am misunderstanding how Fibers is meant to be used

Here's the relevant excerpt from the server
https://gitlab.com/humanitiesNerd/guile-lsp/blob/master/lsp-server.scm#L60

I also partially described the thing here
https://github.com/aconchillo/guile-json/issues/23#issuecomment-445885603

what am I doing wrong ?

Thanks in advance


Re: help with guile-json inconsistencies

2018-12-10 Thread Aleix Conchillo Flaqué
On Mon, Dec 10, 2018 at 4:38 PM Zelphir Kaltstahl
 wrote:
>
> On 10.12.18 23:16, guile-user-requ...@gnu.org wrote:
> > Therefore, one fix would be to make Vector instead of List to
> > corresponds to Json Array, but maybe this change will cause too much
> > breakage, so I am not sure it is practical.
> >
> > Another way would be to make some other type other than Alist to
> > corresponds to Json Object. If we were in Clojure, it would be Hash
> > Map. I think VHash is a good candidate, but I am not happy with it not
> > having a read/write syntax (Hash Table has the same problem too) which
> > makes it not as flexible as Alist.
>
> I think that is how it is done in Racket, if I am not mistaken.
>
>

This is how it's done in guile-json as well. A json object corresponds
to a hash table in guile-json, otherwise it would not be possible to
work properly internally.

The question was not how to parse json and represent it in guile (that
works well), but how to solve an inconsistency when building a json
object from scheme data types. This was done by converting an alist to
a hash table, but unfortunately it doesn't work well in all cases. So,
the solution is that I will remove the conversion from an alist to an
object, so a user will need to explicitly provide a hash table (e.g.
using alist->hash-table). With this change, the bidirectional mapping
mentioned here will be consistent:

https://github.com/aconchillo/guile-json#usage (without the alist note)

Thanks everyone for all the feedback!

Aleix



Re: New library: guile-wikidata

2018-12-10 Thread swedebugia
On 2018-12-09 22:26, Arne Babenhauserheide wrote:
> to...@tuxteam.de writes:
> 
>> On Sun, Dec 09, 2018 at 01:11:05AM -0800, swedebu...@riseup.net wrote:
>>> Hi
>>>
>>> I worked hard for a few days playing with guile.
>>>
>>> Pre-release now at https://gitlab.com/swedebugia/guile-wikidata
>>
>> This is pretty exciting. Hoping to find a relief from my stern project
>> manager...
> 
> That looks pretty cool — I didn’t know wikidata.
> 
> The search procedure looks like it wants to be in the readme as an
> example :-)
> 
> You could add a header and exported main function to also use this
> module as script file:
> 
> Header:
> 
> #!/usr/bin/env bash
> # -*- scheme -*
> exec -a "$0" guile -L "$(dirname "$0")" -e '(wikidata)' -c '' "$@"
> ;; !# ;; this ends the inline comment started by the hashbang
> 
> 
> module:
> 
> ...
>   #:export (show main))
> 
> 
> main:
> 
> (define (main args)
>   (if (null? (cdr args)) (format #t "usage: ... ~s" (first args))
> (let ((query (first args))
>   (count (if (> (len args) 1) (second args) 10)))
>  (search query count
> 
> 
> Add `chmod +x wikidata.scm` and you can run it as
> 
> ./wikidata.scm  []
> 
> 
> Best wishes,
> Arne

Thanks for the tips. 

I now implemented sparql queries as well. See
https://gitlab.com/swedebugia/guile-wikidata

-- 
Cheers 
Swedebugia



Re: Tensorflow bindings

2018-12-10 Thread Aleix Conchillo Flaqué
On Mon, Dec 10, 2018 at 1:27 PM Jan Wedekind  wrote:
>
> Hi,
>
> The current AIscm source now include Tensorflow bindings [1].
> This means that one can now develop machine learning software using Guile
> and Tensorflow. More examples to follow ...
>
> Jan
>
> [1] http://wedesoft.github.io/aiscm/tensorflow.html
>

This is awesome! Thanks!

Aleix



Re: help with guile-json inconsistencies

2018-12-10 Thread John Cowan
On Mon, Dec 10, 2018 at 3:56 PM Alex Vong  wrote:

Therefore, one fix would be to make Vector instead of List to
> corresponds to Json Array, but maybe this change will cause too much
> breakage, so I am not sure it is practical.
>

That is the approach used by the Chicken json egg
.  Note that when writing
you can use either a vector of pairs or a hash table to represent
a JSON object, but when reading it is always re-created as
a vector of pairs.  This is portable and eliminates any problems
with readability from within Scheme.

The json egg depends on the packrat egg at
< http://wiki.call-cc.org/eggref/5/packrat> which has no further
dependencies, but it would be easy to replace the packrat
parser with a hand-rolled parser.

-- 
John Cowan  http://vrici.lojban.org/~cowanco...@ccil.org
If I have seen farther than others, it is because I was looking through a
spyglass with my one good eye, with a parrot standing on my shoulder. --"Y"


> Another way would be to make some other type other than Alist to
> corresponds to Json Object. If we were in Clojure, it would be Hash
> Map. I think VHash is a good candidate, but I am not happy with it not
> having a read/write syntax (Hash Table has the same problem too) which
> makes it not as flexible as Alist.
>
> (Actually, I had been trying to write a reader macro for VHash (w/ or
> w/o the Guile Reader library) but I didn't succeed in doing so because
> of my limited knowledge in how lexing works in Guile.)
>
> > Aleix
>
> Cheers,
> Alex
>


Tensorflow bindings

2018-12-10 Thread Jan Wedekind

Hi,

The current AIscm source now include Tensorflow bindings [1].
This means that one can now develop machine learning software using Guile 
and Tensorflow. More examples to follow ...


Jan

[1] http://wedesoft.github.io/aiscm/tensorflow.html



Re: help with guile-json inconsistencies

2018-12-10 Thread Alex Vong
Hello Aleix,

Aleix Conchillo Flaqué  writes:

> On Sun, Dec 9, 2018 at 10:33 PM Aleix Conchillo Flaqué
>  wrote:
>>
>> On Sun, Dec 9, 2018 at 2:56 AM Aleix Conchillo Flaqué
>>  wrote:
>> >
>> > Hi guilers,
>> >
>> > a new guile-json issue came to me recently:
>> >
>> > https://github.com/aconchillo/guile-json/issues/22
>> >
>> > I don't really have a solution yet on how to solve this, so I would
>> > love some advice. The issue is that one can do:
>> >
>> >   (scm->json '(1 2 3)) which returns [1,2,3]
>> >
>> > however, if you do:
>> >
>> >   (scm->json '((1 2 3)) it returns {"1":[2,3]} but one would probably
>> > expect [[1,2,3]]
>> >   (scm->json '((1 2 3) (4 5 6)) it returns {"1":[2,3], "4":[5,6]} but
>> > one would probably expect [[1,2,3], [4,5,6]]
>> >
>> > I guess the first question is, does everyone else feel the same way
>> > about the return value?
>> >
>> > The problem is that there's a function that checks if something is an
>> > alist by basically checking if it's a pair? recursively and if so, it
>> > builds a json object.
>> >
>>
>> Just to clarify, the problem is not when parsing JSON to scheme data
>> types, this is fine as internally guile-json uses hash tables and
>> lists properly.
>>
>> The problem is with going from scheme to json. For convenience,
>> guile-json doesn't expect a hash table from the user, instead it tries
>> to guess what's a list and what's an alist however, that seems not
>> really distinguishable. That is, there's no way to tell if '((1 2)) is
>> [[1, 2]] or {"1" : [2]} or  {"1" : "2"}.
>>
>> I guess going back to a macro approach for these type of cases would
>> help (even though I had the same problem with my initial macro).
>>
>
> Answering myself again. Re-adding the macro fixes the issue, but with
> a breaking change.
>
> (scm->json '(1 2 3))
>   -> [1,2,3]
>
> (scm->json '((1 2 3) (4 5 6)))
>   -> [[1,2,3],[4,5,6]]
>
> (scm->json (json (object ("key1" "value1") ("key2" (1 2 3)
>   -> {"key2":[1,2,3],"key1":"value1"}
>
> (scm->json `((1 2 3) ,(json (object (4 5)
>   -> [[1,2,3],{"4":5}]
>
> So, the (json) macro is only needed to specify JSON objects, otherwise
> you can use scheme types directly (and lists are always arrays).
>
Another ambuiguity would be that both [] and {} corresponds to ().

It seems to me that the core of this problem is that the Pair, List and
Alist (which is a List of Pairs) types in scheme are not orthogonal,
i.e. () are both List and Alist, and (1 2 3) are both List and Pair.

Therefore, one fix would be to make Vector instead of List to
corresponds to Json Array, but maybe this change will cause too much
breakage, so I am not sure it is practical.

Another way would be to make some other type other than Alist to
corresponds to Json Object. If we were in Clojure, it would be Hash
Map. I think VHash is a good candidate, but I am not happy with it not
having a read/write syntax (Hash Table has the same problem too) which
makes it not as flexible as Alist.

(Actually, I had been trying to write a reader macro for VHash (w/ or
w/o the Guile Reader library) but I didn't succeed in doing so because
of my limited knowledge in how lexing works in Guile.)

> Aleix

Cheers,
Alex


signature.asc
Description: PGP signature


Send/link your favorite guile script

2018-12-10 Thread swedebugia
Dear guilers

RMS once said "to become a programmer you should read lots of code and
write lots of code".

To make this easier I thought out the following:

I would like to receive a link/attached guile script that you are proud
of.

I was thinking of 3 categories:
* below 100 lines
* between 101-299 lines
* longer scripts

If you want to you can send multiple!

Please include a line why you think just this script is
outstanding/nice/choosen.

-- 
Cheers 
Swedebugia



Flattening the learning curve of guile

2018-12-10 Thread swedebugia
Hi

I would like to help improve the manual because the learning curve is
pretty steep at the moment (to me at least) and there a surely many good
examples and helpful think-this-way to put into it.

We could have a whole new section with:
i want to do this: x
in guile this is best done with bla bla, see this project
i want to do this: y
in guile this is best done with bla bla, see this example
...

Also the error messages really need an overhaul. Eg. the "wrong
type"-error is cryptic at best and often you have no idea where it
originates. (I noticed this in my wikidata library where it would pop up
from a low level.)

Also it would be nice to update the guile-webpage with personal stories
how people use guile and a tutorial about porting bash-scripts and
making simple scripts in guile. (we really want people to use guile
instead of bash-scripts don't we?

With simple scripts I mean a script with a main that does something with
100 lines max.

My wikidata library is already way past this so I guess I'm beyond
simple scripting already! \o/

Any thoughts?

-- 
Cheers 
Swedebugia



Re: Guile equivalent to JS promises?

2018-12-10 Thread swedebugia
Hi

On 2018-12-10 15:37, Thompson, David wrote:
> Hello!
> 
> On Sun, Dec 9, 2018 at 5:52 AM  wrote:
>>
>> Hi
>>
>> I'm trying to understand JS promises.
>>
>> Are promises relevant in Guile?
>>
>> According to https://www.promisejs.org/ they seem to be a tool to
>> read/write JSON in a nonblocking way.
>>
>> Is this related to threading where the JS dev want multiple threads to
>> read stuff asynchroniusly at the same time?
> 
> So, promises are basically just callback functions + error handling +
> a way to compose them together in a chain.  I don't know of any
> existing Guile library that implements this API, but it wouldn't take
> much code to make a Scheme equivalent.  However, I am hesitant to
> recommend promises for writing asynchronous programs for a variety of
> reasons. [1]
> 
> Fortunately, Guile is pretty neat and provides a low-level feature
> that allows for much nicer asynchronous programming models: delimited
> continuations. I won't go into much detail about them here (see
> call-with-prompt in the manual), but Andy Wingo's guile-fibers [2]
> project is a really neat asynchronous programming library built on top
> of delimited continuations.
> 
> And here's my favorite guile-user post of all time in which Andy drops
> a 13 line coroutine implementation (this blew my mind many years ago):
> https://lists.gnu.org/archive/html/guile-user/2011-02/msg00031.html
> 
> tl;dr - use a system based on delimited continuations or write your own!
> 
> Hope this helps!
> 
> - Dave
> 
> [1]
> http://wingolog.org/archives/2016/10/12/an-incomplete-history-of-language-facilities-for-concurrency
> [2] https://github.com/wingo/fibers

Thanks for the insights. :)

Guile is indeed pretty neat. Thanks for the link. I started reading some
of wingos blog. Some of it still goes way over my head but i'm learning.

-- 
Cheers 
Swedebugia



Re: Guile equivalent to JS promises?

2018-12-10 Thread Thompson, David
Hello!

On Sun, Dec 9, 2018 at 5:52 AM  wrote:
>
> Hi
>
> I'm trying to understand JS promises.
>
> Are promises relevant in Guile?
>
> According to https://www.promisejs.org/ they seem to be a tool to
> read/write JSON in a nonblocking way.
>
> Is this related to threading where the JS dev want multiple threads to
> read stuff asynchroniusly at the same time?

So, promises are basically just callback functions + error handling +
a way to compose them together in a chain.  I don't know of any
existing Guile library that implements this API, but it wouldn't take
much code to make a Scheme equivalent.  However, I am hesitant to
recommend promises for writing asynchronous programs for a variety of
reasons. [1]

Fortunately, Guile is pretty neat and provides a low-level feature
that allows for much nicer asynchronous programming models: delimited
continuations. I won't go into much detail about them here (see
call-with-prompt in the manual), but Andy Wingo's guile-fibers [2]
project is a really neat asynchronous programming library built on top
of delimited continuations.

And here's my favorite guile-user post of all time in which Andy drops
a 13 line coroutine implementation (this blew my mind many years ago):
https://lists.gnu.org/archive/html/guile-user/2011-02/msg00031.html

tl;dr - use a system based on delimited continuations or write your own!

Hope this helps!

- Dave

[1] 
http://wingolog.org/archives/2016/10/12/an-incomplete-history-of-language-facilities-for-concurrency
[2] https://github.com/wingo/fibers



Re: Guile equivalent to JS promises?

2018-12-10 Thread Neil Jerram
swedebu...@riseup.net writes:

> Hi
>
> I'm trying to understand JS promises.
>
> Are promises relevant in Guile? 
>
> According to https://www.promisejs.org/ they seem to be a tool to
> read/write JSON in a nonblocking way.
>
> Is this related to threading where the JS dev want multiple threads to
> read stuff asynchroniusly at the same time?
>
> -- 
> Cheers 
> Swedebugia

I don't know JS promises, but have you seen
https://www.gnu.org/software/guile/manual/html_node/Delayed-Evaluation.html?

Regards,
   Neil




Re: help with guile-json inconsistencies

2018-12-10 Thread swedebugia

On 2018-12-10 08:27, Aleix Conchillo Flaqué wrote:

On Sun, Dec 9, 2018 at 10:33 PM Aleix Conchillo Flaqué
 wrote:


On Sun, Dec 9, 2018 at 2:56 AM Aleix Conchillo Flaqué
 wrote:


Hi guilers,

a new guile-json issue came to me recently:

https://github.com/aconchillo/guile-json/issues/22

I don't really have a solution yet on how to solve this, so I would
love some advice. The issue is that one can do:

   (scm->json '(1 2 3)) which returns [1,2,3]

however, if you do:

   (scm->json '((1 2 3)) it returns {"1":[2,3]} but one would probably
expect [[1,2,3]]
   (scm->json '((1 2 3) (4 5 6)) it returns {"1":[2,3], "4":[5,6]} but
one would probably expect [[1,2,3], [4,5,6]]

I guess the first question is, does everyone else feel the same way
about the return value?

The problem is that there's a function that checks if something is an
alist by basically checking if it's a pair? recursively and if so, it
builds a json object.



Just to clarify, the problem is not when parsing JSON to scheme data
types, this is fine as internally guile-json uses hash tables and
lists properly.

The problem is with going from scheme to json. For convenience,
guile-json doesn't expect a hash table from the user, instead it tries
to guess what's a list and what's an alist however, that seems not
really distinguishable. That is, there's no way to tell if '((1 2)) is
[[1, 2]] or {"1" : [2]} or  {"1" : "2"}.

I guess going back to a macro approach for these type of cases would
help (even though I had the same problem with my initial macro).



Answering myself again. Re-adding the macro fixes the issue, but with
a breaking change.

(scm->json '(1 2 3))
   -> [1,2,3]

(scm->json '((1 2 3) (4 5 6)))
   -> [[1,2,3],[4,5,6]]

(scm->json (json (object ("key1" "value1") ("key2" (1 2 3)
   -> {"key2":[1,2,3],"key1":"value1"}

(scm->json `((1 2 3) ,(json (object (4 5)
   -> [[1,2,3],{"4":5}]

So, the (json) macro is only needed to specify JSON objects, otherwise
you can use scheme types directly (and lists are always arrays).


Nice to hear you solved it :)

Both Guix and guile-wikidata use guile-json but only from json->scm and 
that works flawlessly. Thanks for creating and maintaining this lib.


--
Cheers
Swedebugia