[racket-users] Re: [ANN] Porting PAIP's Prolog interpreter from Common Lisp to Racket - Part 2

2017-12-26 Thread Zelphir Kaltstahl
This looks very interesting! I am not that far yet, so I don't really have 
any enhancement suggestions, but it is great to see some work being done in 
this area. 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] [ANN] Porting PAIP's Prolog interpreter from Common Lisp to Racket - Part 2

2017-12-26 Thread Luis Marcelo Rosso
Hi all,

I am porting the Prolog interpreter shown in Peter Norvig's classic text on
AI, "Paradigms of Artificial Intelligence Programming: Case Studies in
Common Lisp 1st Edition",
https://www.amazon.com/Paradigms-Artificial-Intelligence-Programming-Studies/dp/1558601910/,
also known as PAIP, in its chapter 11, "Logic Programming".

I have just ended its second version, corresponding to PAIP's sections 11.3
through 11.5, and shared:

   - the code at https://github.com/promesante/paip-racket/, branch
   section-11.3
   - the experience in
   
https://promesante.github.io/2017/12/19/porting_paips_prolog_interpreter_from_common_lisp_to_racket_part_2/

Enhancement suggestions more than welcome.

Cheers

Luis M. Rosso
https://promesante.github.io/
https://github.com/promesante/

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Ownership semantics of string types in the FFI

2017-12-26 Thread Alexis King
I have some library that provides a function that produces a string:

   char* make_string(void);

…and the library expects that I will eventually free the returned memory
using a custom deallocator:

   void free_string(char*);

…can and should I use the _string C type with ffi/unsafe to call this
function? If I write the following:

   (define-mylib make_string (_fun -> _string))

…then when I call (make_string), how does Racket handle the memory of
that block of bytes? Presumably, the bytes returned by the call to
make_string must be copied into memory owned by Racket, but then what
happens to the original buffer? Does Racket call free on it, or is it
left dangling?

Dual to that question, what happens if I have a different API that gives
me a string, but it does NOT yield ownership to me?

   char* lease_string(void);

Once again, if I use the _string C type, will Racket copy the buffer
into a GC’d piece of memory managed by Racket and leave the original
string alone?

My assumption is that is what happens, which means _string will do the
right thing for the second function, but not for the first function,
which means I probably need to instruct Racket to call the free_string
deallocator on the buffer returned by make_string. However, if I use
_string, I no longer have a pointer to the original block of memory,
since Racket will copy it and return the Racket string. What’s the
correct way to instruct the FFI to call the free_string deallocator on
the returned buffer after it has finished copying it into GC-managed
memory?

Alexis

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Using web cells in #lang web-server/insta

2017-12-26 Thread Christian
Hi Jay,

Thanks again for a timely and illustrative answer!

Cheers,
Christian

On 26 December 2017 at 14:09, Jay McCarthy  wrote:
> No, `web-server/lang/web-cells` is for `#lang web-server`
>
> `#lang web-server/insta` is just like `racket` but it includes a call
> to `serve/servlet`
>
> On Tue, Dec 26, 2017 at 5:27 AM, Christian <7enderh...@gmail.com> wrote:
>> Am I correct to assume that when using web cells with #lang
>> web-server/insta, I should (require web-server/lang/web-cells) rather than
>> (require web-server/servlet/web-cells)?
>> (The former implementation seems to have a problem:
>> https://github.com/racket/racket/issues/1918)
>>
>> Thanks for your consideration,
>> Christian
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Using S-Expressions as Persistence

2017-12-26 Thread Philip McGrath
Rather than a module to be run, you can also persist data using `write` and
`read` (perhaps in combination with `serialize` and `deserialize`).

-Philip

On Tue, Dec 26, 2017 at 7:14 AM, Zelphir Kaltstahl <
zelphirkaltst...@gmail.com> wrote:

> Hm that's a point.
> It is only data for a blog, though and if someone got access to the
> hosting machine, they could change my whole program. Still, a valid point
> to consider in other scenarios, when the authors of the persisted data are
> not necessarily the same as the authors of the program which reads those
> persisted files.
>
> On Tuesday, December 26, 2017 at 6:43:13 AM UTC+1, David K. Storrs wrote:
>>
>> There's a security issue in that if someone managed to modify your
>> persistence file they could use it to execute arbitrary code when you
>> read it in.
>>
>> On Mon, Dec 25, 2017 at 7:26 AM, Zelphir Kaltstahl
>>  wrote:
>> > I wrote some program which uses the `yaml` library to parse some data
>> files.
>> >
>> >
>> > However, this morning, I had an idea. I often read, that XML is sort of
>> a
>> > more verbose form of S-Expressions or that it at least could be
>> replaced by
>> > S-Expressions. So why not use that instead of YAML? Why not simply put
>> the
>> > data into S-Expressions in those files and simply `require` them?
>> >
>> > For example lets say I have some struct:
>> >
>> > ~~~
>> > (struct Abc (member1 member2))
>> > ~~~
>> >
>> > I could simply write in that data file:
>> >
>> > ~~~
>> > #lang racket
>> >
>> > (provide (all-defined-out))
>> >
>> > (make-Abc data1 data2)
>> > ~~~
>> >
>> > This would probably even increase speed, because I'd not have to parse
>> the
>> > thing, but interpret S-Expressions directly.
>> > With the magic of macros, I guess it could be as little text a some
>> YAML
>> > file. Besides, who cares about a few more parentheses anyway.
>> > Oh and I would not have to worry about types, because they are already
>> in
>> > the data file. For example if I want to make a datetime, I'd use the
>> > appropriate S-Expression for doing that immediately or define some
>> function
>> > for it to make it easier to read.
>> >
>> > Is there any downside to this approach, compared to reading some YAML
>> file?
>> > (Why am I even reading a YAML file!)
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Racket Users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an
>> > email to racket-users...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Using web cells in #lang web-server/insta

2017-12-26 Thread Jay McCarthy
No, `web-server/lang/web-cells` is for `#lang web-server`

`#lang web-server/insta` is just like `racket` but it includes a call
to `serve/servlet`

On Tue, Dec 26, 2017 at 5:27 AM, Christian <7enderh...@gmail.com> wrote:
> Am I correct to assume that when using web cells with #lang
> web-server/insta, I should (require web-server/lang/web-cells) rather than
> (require web-server/servlet/web-cells)?
> (The former implementation seems to have a problem:
> https://github.com/racket/racket/issues/1918)
>
> Thanks for your consideration,
> Christian
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
-=[ Jay McCarthy   http://jeapostrophe.github.io]=-
-=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Using web cells in #lang web-server/insta

2017-12-26 Thread Christian

   
   - Am I correct to assume that when using web cells with #lang 
   web-server/insta, I should (require web-server/lang/web-cells) rather 
   than (require web-server/servlet/web-cells)?
   - (The former implementation seems to have a 
   problem: https://github.com/racket/racket/issues/1918)

Thanks for your consideration,
Christian

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.