[racket-users] Can no longer interactively enter! module from the shell

2020-08-09 Thread Greg Rosenblatt
Given a module defined in example.rkt:
```
#lang racket/base
(provide example)

(displayln "loading example")

(define example 5)
```

I used to be able to enter example.rkt with an interactive session from the 
shell like this:

> racket -ie '(enter! "example.rkt")'
Welcome to Racket v7.3.
loading example
> example
; example: undefined;
;  cannot reference an identifier before its definition
;   in module: top-level
; [,bt for context]
> ,bt
; example: undefined;
;  cannot reference an identifier before its definition
;   in module: top-level
;   context...:
;eval-one-top12
;/Applications/Racket v7.3/share/pkgs/xrepl-lib/xrepl/xrepl.rkt:1477:0
;/Applications/Racket v7.3/collects/racket/repl.rkt:11:26


The module still seems to be loading, but my interactive session hasn't 
started in the module context.  Racket 6 used to start my interactive 
session in the module context.

Was this change in behavior intended?  Is there a new way to achieve what 
I'm trying to do?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/bbaf1e21-52e8-4514-9b8c-20db6357fb40o%40googlegroups.com.


[racket-users] Can Racket implement LockedMagicDoor example of MIXEDJAVA?

2020-08-09 Thread Siyuan Chen
Hi all,

Recently I read the paper "Classes and Mixins" by Matthew Flatt, Shriram
Krishnamurthi and Matthias Felleisen.

In this paper, the authors presented MIXEDJAVA.

In MIXEDJAVA,

> A programmer implements mixins in exactly the same
> way as a derived class, except that the programmer cannot
> rely on the implementation of the mixin's superclass, only
> on its interface. We consider this an advantage of mixins
> because it enforces the maxim "program to an interface, not
> an implementation".
>
It is very close to the mixin form in Racket, because we can specific
interface in the mixin form:

```
(mixin (interface-expr ...) (interface-expr ...)
  class-clause ...)
```

In Chapter 3, they also introduced an example (a maze adventure game, I
called it LockedMagicDoor) which uses the system.

My question is:

Is it possible to implement LockedMagicDoor in Racket?


I did some experiments but failed.

See following code (or
https://gist.github.com/chansey97/aecffabb2885c83fa040ba677bde5de4):

```
#lang racket

(define the-key 'the-key)
(define the-spell-book 'the-spell-book)

(define person%
  (class object%
(init-field items h)
(super-new)

(define/public (has-item item)
  (member item items))

(define/public (height)
  h)
))

(define door<%> (interface () can-open can-pass))

(define door-mixin
  (mixin () (door<%>)
(super-new)

(define/public (can-open p)
  (println "door% can-open")
  #t)

(define/public (can-pass p)
  (println "door% can-pass")
  #t)
))

(define secure-door<%> (interface (door<%>) needed-item))

(define secure-mixin
  (mixin (door<%>) (secure-door<%>)
(super-new)

(define/public (needed-item) ;; error??
  (println "secure-mixin needed-item")
  #f)

(define/override (can-open p)
  (println "secure-mixin can-open")
  (define item (needed-item))
  (cond
((not (send p has-item item)) (printf "You don't have the Key ~v\n"
item)
  #f)
(else (printf "Using Key... ~v\n" item)
  (super can-open p
))

(define locked-needed-mixin
  (mixin (secure-door<%>) (secure-door<%>)
(super-new)
(define/override (needed-item)
  (println "locked-needed-mixin neededItem")
  the-key)
))

(define magic-needed-mixin
  (mixin (secure-door<%>) (secure-door<%>)
(super-new)
(define/override (needed-item)
  (println "magic-needed-mixin neededItem")
  the-spell-book)
))

(define door%
  (door-mixin object%))

(define locked-mixin (compose locked-needed-mixin secure-mixin))
(define magic-mixin (compose magic-needed-mixin secure-mixin))

(define locked-magic-mixin (compose locked-mixin magic-mixin))
(define locked-magic-door% (locked-magic-mixin door%))

(define door (new locked-magic-door%))
(send door can-open (new person% [items (list the-key the-spell-book)] [h
0.5]))

; class*: superclass already contains method
;   superclass: #
;   method name: needed-item
;   class name: ...agic-door-failed.rkt:36:2

```

The problem is how to implement `secure-mixin`?

Notice that since the `secure-mixin` is mixed into `locked-magic-door%`
twice, there will be two `needed-item` methods in the inheritance chain, so
they are naming conflict.

However in MIXEDJAVA, they do not conflict:

> Specifically, a composition m1 compose m2 contains two methods named
> x if both m1 and m2 declare x and m1's inheritance interface does not
> contain x. Both x methods are accessible in an instance of the composite
> mixin since the object can be viewed specifically as an instance of m1 or
> m2.
>
Can someone help me? (e.g. make some changes to this code above and let it
work in Racket)

Very thanks.


I also attempt to use Inner to simulate the behavior of MIXEDJAVA:

```
(define secure-mixin
  (mixin (door<%>) (secure-door<%>)
(super-new)

(define/pubment (needed-item)
  (println "secure-mixin needed-item")
  #f)

(define/override (can-open p)
  (println "secure-mixin can-open")
  (define item (inner #f needed-item))
  (cond
((not (send p has-item item)) (printf "You don't have the Key ~v\n"
item)
  #f)
(else (printf "Using Key... ~v\n" item)
  (super can-open p
))

(define locked-needed-mixin
  (mixin (secure-door<%>) (secure-door<%>)
(super-new)
(define/augride (needed-item)
  (println "locked-needed-mixin neededItem")
  the-key)
))

(define magic-needed-mixin
  (mixin (secure-door<%>) (secure-door<%>)
(super-new)
(define/augride (needed-item)
  (println "magic-needed-mixin neededItem")
  the-spell-book)
))
```

But still failed:

; class*: superclass already contains method
;   superclass: #
;   method name: needed-item

See https://gist.github.com/chansey97/264d3435a8f506153709cc9804227fdf

PS: I also tried `overment` and `augment` for the `needed-item` in
`secure-mixin`, but failed as well 

[racket-users] Announce: Plisqin 0.4

2020-08-09 Thread Ryan Kramer
I've just finished some final cleanup and testing of Plisqin and am ready 
to call it "stable, but incomplete".

https://docs.racket-lang.org/plisqin/index.html

Plisqin's semantics are similar to SQL but there are some key differences. 
Perhaps the most significant is that joins are values, not language 
constructs.

Plisqin is incomplete in that it still lacks first-class 
Insert/Update/Delete support. However, it is easy to mix in arbitrary SQL 
pretty much anywhere you want, so this might not be a problem depending on 
your use case.

With this release I will be taking a break from any major work on Plisqin. 
Bugfixes and small enhancements should be no problem though.

If you decide to try Plisqin from source, be aware that a few tests will 
fail on Racket CS due to differences in the Printer. As long as your code 
does not depend on any printable representations it will be fine.

A big "Thank You!" to everyone who has made the Racket ecosystem so great, 
and special thanks to everyone who helped me with my questions.

- Ryan Kramer

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/24be7b61-3719-405b-9966-920fd55792aco%40googlegroups.com.


Re: [racket-users] Strange performance behavior

2020-08-09 Thread sleepnova
Oh, I got it. Thank you for the explanation!

George Neuner  於 2020年8月9日 週日 下午1:35寫道:

>
> On 8/9/2020 1:20 AM, wanp...@gmail.com wrote:
> >
> > One more thing which bothers me is if I put a (collect-garbage) in
> > front of the testing, I got gc time: 0 if not I got gc time: 9.
> > Why can't 1 gc reclaim all memory during execution while it can before
> > executes?
>
> Those numbers show *time* spent working, not what was done.  If you
> collect before running your program, at that point little has been
> allocated, and little or nothing has been freed, and so the GC has
> little to do ... hence it spends '0' time doing it  [zero meaning below
> the resolution of the computer's clock].  Once your program starts
> running, memory is being allocated and freed, and so a GC in the middle
> or at the end has much more work to do.
>
> George
>
>
>

-- 
- sleepnova
呼叫小黃創辦人 & CEO

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABa2-7PZ_Yhr7_5nqTjBA09hExyWOdM0gyQAvuOhGFb8XwbivA%40mail.gmail.com.