Re: [racket-users] Problems with modules and with raco

2016-08-14 Thread rumpz
Thank you for the suggestions. I've tried to do the following to test your 
guess:

-deleted everything except the source files
-raco exe app.rkt
-raco exe eng.rkt

(app is the web app, eng the program I use to create the files with the 
serialized data, words contains the serializable-struct and the functions to 
load and save it)

-raco distribute papp app eng 
-cd papp/bin
-./eng-> it correctly creates the data and saves them in a file
-./app-> when it tries to access the file to load the data it crashes with 
this error:

dynamic-require: unknown module
  module name: #
  context...:
   /usr/share/racket/collects/racket/private/serialize.rkt:654:8: loop
   /usr/share/racket/collects/racket/private/serialize.rkt:649:2: deserialize
   #%mzc:app: [running body]




On Sunday, August 14, 2016 at 12:39:32 AM UTC+2, Matthew Flatt wrote:
> Just after sending, I realized that you may be running a program like
> "app.rkt" directly with `racket`, and then trying to deserialize from
> an application created with `raco exe`. That would fail in much the way
> you describe for my example.
> 
> If that's the problem, then one possible solution is to generate the
> serialized data after creating an executable. Creating the data that
> way might not be desirable or practical, though.
> 
> Another approach is to use a collection/package. When you create an
> executable, `racket` goes out of its way to hide path information from
> the original context; that's why data serialized based on running a
> file will no deserialize in a `raco exe` executable, because the only
> identity of the `serializable-struct` declaration is the filesystem
> path of its containing module. In contrast to filesystem path, `raco
> exe` preserves collection-mapping information. So, if you serialized
> data based on a module referenced through a collection path, it will
> work for the `raco exe` executable.
> 
> Concretely:
> 
>  * Put "app.rkt" in a collection/package. I'll call it "app":
> 
>  $ mkdir app
>  $ mv app.rkt words.rkt app/
>  $ raco pkg install app/
> 
>  * Run the application using a module path, as opposed to a filesystem
>path:
> 
>  $ racket -l app/app
>  ((3) 1 (((lib "app/words.rkt") )
> 
>  # Not this way:
>  $ racket app/app.rkt
>  ((3) 1 ((#"/tmp/app/words.rkt" .)
> 
>  * Unfortunately, `raco exe` doesn't currently know how to make an
>executable based on a module path. So, make a module that refers to
>"app.rkt" through it's module path:
> 
>  go.rkt:
>#lang racket/base
>(require app/app)
> 
>Then create an executable from "go.rkt":
> 
>  $ raco exe go.rkt
>  $ raco dist go-dist go
>  $ ./go-dist/bin/go
> 
> That `./go-dist/bin/go` will work with serialized data produced by
> `racket -l app/app`.
> 
> 
> Hope that helps,
> Matthew
> 
> 
> At Sat, 13 Aug 2016 16:25:44 -0600, Matthew Flatt wrote:
> > I think we need more of your program to help. In particular, I don't
> > know what you have in mind with `(define-namespace-anchor a)`, and I
> > wonder whether your program uses `load` or `dynamic-require`.
> > 
> > 
> > I tried completing your example with
> > 
> > app.rkt:
> > 
> >  #lang racket
> >  (require "words.rkt"
> >   racket/serialize)
> > 
> >  ;; write serialized
> >  (writeln (serialize (word 1 2)))
> >  ;; read something that must have been previously serialized
> >  (deserialize (read (current-input-port)))
> > 
> >  
> > words.rkt:
> > 
> >  #lang racket
> >  (require racket/serialize)
> >  (provide (struct-out word))
> > 
> >  (serializable-struct word
> >(type
> > ecc.))
> > 
> > but that works as expected, where the serialized output has something
> > like "#%embedded:g2140:words" instead of a path.
> > 
> > 
> > At Fri, 12 Aug 2016 05:53:35 -0700 (PDT), rumpz wrote:
> > > app.rkt:
> > > 
> > > #lang racket
> > > (require "words.rkt"
> > >web-server/servlet)
> > > 
> > > 
> > > 
> > > 
> > > words.rkt:
> > > 
> > > #lang racket
> > > (require racket/serialize)
> > > (provide (struct-out word) save-words load-words decline)
> > > 
> > > (serializable-struct word
> > >   (type
> > >ecc.))
> > > 
> > > (define-namespace-anchor a)
> > > (define ns (namespace-anchor->namespace a))
> > > 
> > > 
> > > 
> > > 
> > > If I compile app.rkt with "raco exe app.rkt" and "raco distribute appdir 
> > > app"
> > > and I move the "appdir" directory to another system, when I run ./app it 
> > > crashes with this error:
> > > 
> > > default-load-handler: cannot open module file
> > >   module path: #
> > >   path: /home/rumpz/webapp/words.rkt
> > >   system error: No such file or directory; errno=2
> > >   context...:
> > >standard-module-name-resolver
> > >/usr/share/racket/collects/racket/private/serialize.rkt:654:8: loop
> > >/usr/share/racket/collects/racket/private/serialize.rkt:649:2: 
> > > 

Re: [racket-users] Problems with modules and with raco

2016-08-13 Thread Matthew Flatt
Just after sending, I realized that you may be running a program like
"app.rkt" directly with `racket`, and then trying to deserialize from
an application created with `raco exe`. That would fail in much the way
you describe for my example.

If that's the problem, then one possible solution is to generate the
serialized data after creating an executable. Creating the data that
way might not be desirable or practical, though.

Another approach is to use a collection/package. When you create an
executable, `racket` goes out of its way to hide path information from
the original context; that's why data serialized based on running a
file will no deserialize in a `raco exe` executable, because the only
identity of the `serializable-struct` declaration is the filesystem
path of its containing module. In contrast to filesystem path, `raco
exe` preserves collection-mapping information. So, if you serialized
data based on a module referenced through a collection path, it will
work for the `raco exe` executable.

Concretely:

 * Put "app.rkt" in a collection/package. I'll call it "app":

 $ mkdir app
 $ mv app.rkt words.rkt app/
 $ raco pkg install app/

 * Run the application using a module path, as opposed to a filesystem
   path:

 $ racket -l app/app
 ((3) 1 (((lib "app/words.rkt") )

 # Not this way:
 $ racket app/app.rkt
 ((3) 1 ((#"/tmp/app/words.rkt" .)

 * Unfortunately, `raco exe` doesn't currently know how to make an
   executable based on a module path. So, make a module that refers to
   "app.rkt" through it's module path:

 go.rkt:
   #lang racket/base
   (require app/app)

   Then create an executable from "go.rkt":

 $ raco exe go.rkt
 $ raco dist go-dist go
 $ ./go-dist/bin/go

That `./go-dist/bin/go` will work with serialized data produced by
`racket -l app/app`.


Hope that helps,
Matthew


At Sat, 13 Aug 2016 16:25:44 -0600, Matthew Flatt wrote:
> I think we need more of your program to help. In particular, I don't
> know what you have in mind with `(define-namespace-anchor a)`, and I
> wonder whether your program uses `load` or `dynamic-require`.
> 
> 
> I tried completing your example with
> 
> app.rkt:
> 
>  #lang racket
>  (require "words.rkt"
>   racket/serialize)
> 
>  ;; write serialized
>  (writeln (serialize (word 1 2)))
>  ;; read something that must have been previously serialized
>  (deserialize (read (current-input-port)))
> 
>  
> words.rkt:
> 
>  #lang racket
>  (require racket/serialize)
>  (provide (struct-out word))
> 
>  (serializable-struct word
>(type
> ecc.))
> 
> but that works as expected, where the serialized output has something
> like "#%embedded:g2140:words" instead of a path.
> 
> 
> At Fri, 12 Aug 2016 05:53:35 -0700 (PDT), rumpz wrote:
> > app.rkt:
> > 
> > #lang racket
> > (require "words.rkt"
> >  web-server/servlet)
> > 
> > 
> > 
> > 
> > words.rkt:
> > 
> > #lang racket
> > (require racket/serialize)
> > (provide (struct-out word) save-words load-words decline)
> > 
> > (serializable-struct word
> >   (type
> >ecc.))
> > 
> > (define-namespace-anchor a)
> > (define ns (namespace-anchor->namespace a))
> > 
> > 
> > 
> > 
> > If I compile app.rkt with "raco exe app.rkt" and "raco distribute appdir 
> > app"
> > and I move the "appdir" directory to another system, when I run ./app it 
> > crashes with this error:
> > 
> > default-load-handler: cannot open module file
> >   module path: #
> >   path: /home/rumpz/webapp/words.rkt
> >   system error: No such file or directory; errno=2
> >   context...:
> >standard-module-name-resolver
> >/usr/share/racket/collects/racket/private/serialize.rkt:654:8: loop
> >/usr/share/racket/collects/racket/private/serialize.rkt:649:2: 
> > deserialize
> >#%mzc:app: [running body]
> > 
> > 
> > Even if I don't move from my system but just rename words.rkt, it still 
> > crashes. From the examples and the documentation I assumed that raco 
> > automatically included required modules, but it looks like it's just 
> > looking 
> > for the .rkt file (and even with the exact path that it has on the original 
> > system). What am I doing wrong?
> > 
> > Also, a secondary problem with modules that may be related: I've tried to 
> make 
> > a copy of the "webapp" directory, called webapp2. When I launch app from 
> > the 
> > new directory, it loads a list of "word" structures from a file I saved 
> > them 
> > in previously, and try to access them with a "word" field (like 
> > "word-type") 
> > it crashes with:
> > 
> > word-type: contract violation;
> >  given value instantiates a different structure type with the same name
> >   expected: word?
> >   given: #
> > 
> > It's like it marked down somewhere that those structs refer to the 
> definition 
> > of "word" in webapp/words.rkt, and not the one in webapp2/words.rkt
> > 
> > -- 
> > You received this message because you are subscribed 

Re: [racket-users] Problems with modules and with raco

2016-08-13 Thread Matthew Flatt
I think we need more of your program to help. In particular, I don't
know what you have in mind with `(define-namespace-anchor a)`, and I
wonder whether your program uses `load` or `dynamic-require`.


I tried completing your example with

app.rkt:

 #lang racket
 (require "words.rkt"
  racket/serialize)

 ;; write serialized
 (writeln (serialize (word 1 2)))
 ;; read something that must have been previously serialized
 (deserialize (read (current-input-port)))

 
words.rkt:

 #lang racket
 (require racket/serialize)
 (provide (struct-out word))

 (serializable-struct word
   (type
ecc.))

but that works as expected, where the serialized output has something
like "#%embedded:g2140:words" instead of a path.


At Fri, 12 Aug 2016 05:53:35 -0700 (PDT), rumpz wrote:
> app.rkt:
> 
> #lang racket
> (require "words.rkt"
>web-server/servlet)
> 
> 
> 
> 
> words.rkt:
> 
> #lang racket
> (require racket/serialize)
> (provide (struct-out word) save-words load-words decline)
> 
> (serializable-struct word
>   (type
>ecc.))
> 
> (define-namespace-anchor a)
> (define ns (namespace-anchor->namespace a))
> 
> 
> 
> 
> If I compile app.rkt with "raco exe app.rkt" and "raco distribute appdir app"
> and I move the "appdir" directory to another system, when I run ./app it 
> crashes with this error:
> 
> default-load-handler: cannot open module file
>   module path: #
>   path: /home/rumpz/webapp/words.rkt
>   system error: No such file or directory; errno=2
>   context...:
>standard-module-name-resolver
>/usr/share/racket/collects/racket/private/serialize.rkt:654:8: loop
>/usr/share/racket/collects/racket/private/serialize.rkt:649:2: deserialize
>#%mzc:app: [running body]
> 
> 
> Even if I don't move from my system but just rename words.rkt, it still 
> crashes. From the examples and the documentation I assumed that raco 
> automatically included required modules, but it looks like it's just looking 
> for the .rkt file (and even with the exact path that it has on the original 
> system). What am I doing wrong?
> 
> Also, a secondary problem with modules that may be related: I've tried to 
> make 
> a copy of the "webapp" directory, called webapp2. When I launch app from the 
> new directory, it loads a list of "word" structures from a file I saved them 
> in previously, and try to access them with a "word" field (like "word-type") 
> it crashes with:
> 
> word-type: contract violation;
>  given value instantiates a different structure type with the same name
>   expected: word?
>   given: #
> 
> It's like it marked down somewhere that those structs refer to the definition 
> of "word" in webapp/words.rkt, and not the one in webapp2/words.rkt
> 
> -- 
> 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.


[racket-users] Problems with modules and with raco

2016-08-12 Thread rumpz
app.rkt:

#lang racket
(require "words.rkt"
 web-server/servlet)




words.rkt:

#lang racket
(require racket/serialize)
(provide (struct-out word) save-words load-words decline)

(serializable-struct word
  (type
   ecc.))

(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))




If I compile app.rkt with "raco exe app.rkt" and "raco distribute appdir app"
and I move the "appdir" directory to another system, when I run ./app it 
crashes with this error:

default-load-handler: cannot open module file
  module path: #
  path: /home/rumpz/webapp/words.rkt
  system error: No such file or directory; errno=2
  context...:
   standard-module-name-resolver
   /usr/share/racket/collects/racket/private/serialize.rkt:654:8: loop
   /usr/share/racket/collects/racket/private/serialize.rkt:649:2: deserialize
   #%mzc:app: [running body]


Even if I don't move from my system but just rename words.rkt, it still 
crashes. From the examples and the documentation I assumed that raco 
automatically included required modules, but it looks like it's just looking 
for the .rkt file (and even with the exact path that it has on the original 
system). What am I doing wrong?

Also, a secondary problem with modules that may be related: I've tried to make 
a copy of the "webapp" directory, called webapp2. When I launch app from the 
new directory, it loads a list of "word" structures from a file I saved them in 
previously, and try to access them with a "word" field (like "word-type") it 
crashes with:

word-type: contract violation;
 given value instantiates a different structure type with the same name
  expected: word?
  given: #

It's like it marked down somewhere that those structs refer to the definition 
of "word" in webapp/words.rkt, and not the one in webapp2/words.rkt

-- 
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.