Re: [racket-users] format-id question

2016-05-09 Thread Benjamin Greenman
On Mon, May 9, 2016 at 1:41 PM, Kevin Forchione  wrote:

> (with-syntax ([name (format-id stx "~a-~a" #'a #'b)])


Change this line to:

(with-syntax ([name (format-id stx "~a-~a" (syntax-e #'a) (syntax-e #'b))])

Using syntax-e explicitly gets the value out of the syntax objects #'a &
#'b.

(I'm not sure why the original worked)

-- 
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] Alternative to interfaces/type classes in Typed Racket

2016-04-24 Thread Benjamin Greenman
On Sun, Apr 24, 2016 at 1:47 PM, Daniel Karch  wrote:

> how this could be done with structures


One way is to consider the struct definition as an interface. Then
different values can implements the same interface & be used in a uniform
way.

Here's a struct that I used as an interface for web scrapers. (Scraping
definitions of English words from dictionary web sites)
https://github.com/bennn/iPoe/blob/master/ipoe/private/scrape/scrape-words.rkt#L42

With that definition (and `prop:procedure` to make instances of the struct
callable), it's easy to write a function that queries a bunch of web
scrapers in order and returns as soon as one scraper finds a result.
https://github.com/bennn/iPoe/blob/master/ipoe/private/scrape/scrape-words.rkt#L32

The above code is untyped, but should work in Typed Racket. If you want I
can port an example.

-- 
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] hash-clear*

2016-04-24 Thread Benjamin Greenman
I think you want hash-clear! because I think you're using a mutable
hashtable.

hash-clear! is for mutable hashtables (built with make-hash, added to with
hash-add!) and returns void after it updates its argument
hash-clear is for immutable hashes (build with hash or for/hash, added to
with hash-add) and returns a new hashtable -- for example:

> (define h (hash 'a 1))

> (define i (hash-clear h))

> (hash-count h)
1

> (hash-count i)
0

The notes on chaperones & impersonators are only about efficiency. They
shouldn't affect your choice.

On Sun, Apr 24, 2016 at 5:11 AM, Damien Mattei 
wrote:

> hi,
>
> what is the best way to clear a hash table, hash-clear or hash-clear! ? if
> the hash-table is defined in a code at top-level and used in functions as a
> global variable, the issue i have is that when at REPL i use a first time
> my function (that use hash-table) it's ok but when i reuse the function it
> returns a wrong result as the hash-table is not redefined and cleared and
> has data in it that make interfere with reuse of hash-table, so i need to
> clear it ...
> i tried to read the story about chaperone and impersonator in the doc but
> my english and the specificities of drracket scheme make that i do not
> understand which of hash-clear or hash-clear!  is more appropriate in this
> case.
>
> regards,
>
> damien
>
> --
> 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] Re: What do you use macros for?

2016-04-11 Thread Benjamin Greenman
Today I decided to convert all structure definitions in a Typed Racket file
to lists. For instance,

(struct foo ([x : Integer]))


would become a tagged list:

(define-type foo (Pairof 'foo (List Integer)))

along with a constructor, predicate, and accessors.

Using a macro, I was able to write what I wanted to do once and use it for
multiple structures.
Here's how it looked in one file: all I had to do was write the macro, use
"struct2" instead of "struct", and remove uses of "struct-out". Other files
in the project worked with the new data definition, no problems.

#lang typed/racket
(require (for-syntax racket/base syntax/parse racket/syntax))

(define-syntax (struct2 stx)
  (syntax-parse stx #:datum-literals (:)
   [(_ name:id ([f*:id : t*] ...))
#:with ((name-f* i*) ...)
  (for/list ([f (in-list (syntax-e #'(f* ...)))]
 [i (in-naturals 1)])
(list (format-id stx "~a-~a" (syntax-e #'name) (syntax-e f)) i))
#:with Name (format-id stx "~a" (string-titlecase (symbol->string
(syntax-e #'name
#:with name? (format-id stx "~a?" (syntax-e #'name))
(syntax/loc stx (begin
  (define-type Name (Pairof 'name (Listof Any)))
  (provide Name)
  (define (name (f* : t*) ...) : Name
(list 'name f* ...))
  (provide name)
  (define (name-f* (p : Name)) : t*
(cast (list-ref p 'i*) t*))
  ...
  (provide name-f* ...)
  (define (name? (v : Any)) : Boolean
(and (list? v) (not (null? v)) (eq? 'name (car v  ))]))

(struct2 posn ([x : Real]
   [y : Real]))
(struct2 block ([x : Real]
[y : Real]
[color : Symbol]))
(struct2 tetra ([center : Posn]
[blocks : (Listof Block)]))
(struct2 world ([tetra : Tetra]
[blocks : (Listof Block)]))

(: posn=? (-> Posn Posn Boolean))
(define (posn=? p1 p2)
  (and (= (posn-x p1) (posn-x p2))
   (= (posn-y p1) (posn-y p2

(provide posn=?)


(Nevermind why I did this, or why I used "Any" and "cast". Hopefully the
macro is interesting.)

-- 
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] Re: Problem with # and mutable lists

2016-04-11 Thread Benjamin Greenman
>
> but although I changed else expresion, Racket sometimes returns same
> warning(but now with #f instead of #).


After you call `select-room`, you'll want to check that the result is an
mlist (instead of #f or #) before calling mcdr.

-- 
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] Problem with # and mutable lists

2016-04-10 Thread Benjamin Greenman
On Sun, Apr 10, 2016 at 7:29 AM, Joan Martin  wrote:

> I use it without problems : (select-room 2 environment) in this case.
> But when I use it in another procedure (for example: set-symbol),
> sometimes Racket returns this:
>
>   mcdr: contract violation;;(mcdr in let in set-symbol)
>   expected: mpair?
>   given: #;;(returned by select-room ?)
>

This problem may be because your first if-statement in select-room is
missing an else branch.



>
> In Racket documentation I found : " # is returned by most forms and
> procedures that have a side-effect and no useful result."
>

These functions return # because the useful result is usually the
argument you passed the procedure in the first place. The example below
uses set-mcar! to update a list -- the useful result is the original list,
not the result of set-mcar!

#lang racket/base

(define lst (mcons 1 (mcons 2 '(

(displayln lst)
;; (1 2)

(set-mcar! lst 3)

(displayln lst)
;; (3 2)

-- 
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: FW: [racket-users] macros within expressions.

2016-04-06 Thread Benjamin Greenman
This is "bad syntax" for the same reason that `(map or '())` is "bad
syntax".
When the macro expander sees `(map y-coord points)`, it recognizes `map` as
a variable binding and then tries expanding each argument to `map`.
Expanding `y-coord` by itself leads to the error.

You could instead define `y-coord` as an identifier macro or just alias it
as a function. (As Daniel & Jos recommend.)

(define-syntax (y-coord stx) ;; Identifier macro
  (syntax-case stx ()
[y-coord:id #'point-y]))

(define y-coord point-y) ;; Function


For details on the expander:
http://docs.racket-lang.org/reference/syntax-model.html#%28part._expand-steps%29

-- 
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] racket not W^X?

2016-04-05 Thread Benjamin Greenman
>
> [Still waiting for the verified compiler guys to look at reflective
> methods.
>

http://www.mpi-sws.org/~marcopat/marcopat/Publications_files/paper_4%20%283%29.pdf

(They give the attacker an alpha-equivalence predicate. It's a start.)

-- 
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 #lang agile

2016-03-31 Thread Benjamin Greenman
Finally, the language for agile 
software development.
https://github.com/bennn/agile
(raco pkg install agile)

Featuring:
- Concise, unambiguous syntax

- Time-tested suite of primitive datatypes

- Syntax tools  to
meet changing requirements
- Fully compatible with the Racket 
programming language and build tools


Agile programs start with `#lang agile`. The rest is up to you.

#lang agile

(begin-for-syntax (define-syntax-class principle
  #:attributes (message)
  (pattern (word*:id ...)
   #:attr message #'(word* ...

(define-syntax make-manifesto
  (syntax-parser
   [(_ p*:principle ...)
#:with (i* ...)
  (for/list ([p (in-list (syntax-e #'(p* ...)))]
 [i (in-naturals 1)])
i)
#'(lambda (n)
(case n
 [(i*) 'p*.message]
 ...
 [else '(responding to change)]))]))

(define agile
  (make-manifesto
   [satisfy the customer]
   [welcome changing requirements]
   [deliver working software]
   [work together daily]
   [support and trust]
   [face-to-face conversation]
   [working software]
   [sustainable development]
   [attention to excellence]
   [simplicity is essential]
   [self-organizing teams]
   [reflect tune adjust]))

(agile 12)
;; '(reflect tune adjust)

(Joking aside, any day of the year is a good day to be programming in
Racket)

-- 
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] serialization of math/array

2016-03-30 Thread Benjamin Greenman
Here's one hack.

#lang racket/base

(require
  math/array
 (prefix-in rkt: racket/serialize))

(define secret-key 'array)

(define (serialize val)
  (if (array? val)
(rkt:serialize (cons secret-key (array->list val)))
(rkt:serialize val)))

(define (deserialize val)
  (define d (rkt:deserialize val))
  (if (and (pair? d) (eq? secret-key (car d)))
(list->array (cdr d))
d))

(define arr (array #[0 1 2]))
(serialize arr)
(deserialize (serialize arr))

(Part of the issue serializing math/array is that it represents arrays as
functions under the hood)

-- 
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] How to manage a Racket package within a Git repo?

2016-03-23 Thread Benjamin Greenman
Ok, that would help


On Wed, Mar 23, 2016 at 2:21 PM, Matthew Flatt  wrote:

> Are there other places where you looked that could also use a note?
>

Only pkgs.racket-lang.org, but I think the note in "getting started" should
be enough.

-- 
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] How to manage a Racket package within a Git repo?

2016-03-23 Thread Benjamin Greenman
Great, thank you

-- 
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] How to manage a Racket package within a Git repo?

2016-03-23 Thread Benjamin Greenman
Thank you!

Is this documented / is there a good place to add a note in the docs?
(Maybe the package server should have an FAQ link, besides just linking to
docs.racket-lang.org ?)

-- 
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] How to manage a Racket package within a Git repo?

2016-03-23 Thread Benjamin Greenman
I have a git repo that contains a Racket package. The repo also contains
other folders related to the package. How do I share the package on
pkgs.racket-lang.org without sharing (or just compiling/installing) the
other folders?


Say I ("bennn") own a repo "foo" with 2 folders, "pkg" and "other". I want
to put "pkg" on pkgs.racket-lang.org.

- First, I tried changing the Source field of the package to reference "
github.com/bennn/foo/tree/master/pkg". Seems no different from "
github.com/bennn/foo".

- I do not want to move "other" to a new repo.

- My current solution is to put an info.rkt file at the top of my repo with:

#lang info

(define collection 'multi)

(define setup-collects '("pkg"))

(define compile-omit-paths '("other"))

Both setup-collects and compile-omit-paths are necessary, for getting `raco
setup` and `raco pkg` to do the right thing. Is there a better way?

-- 
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] regexp-match? problem

2016-03-11 Thread Benjamin Greenman
I'm glad you found #px. The issue here is that bounded repetitions like
{1,2} are not part of the #rx grammar.
But #px supports them just fine.

http://docs.racket-lang.org/reference/regexp.html

On Fri, Mar 11, 2016 at 5:38 PM, Héctor Mc  wrote:

>
> Hey, I have this problem, I want filter values from DPTO1 to
> DPTO99 (DPTO is a word with letter O not zero) but I don't
> get that. with #rx mark error/false with DPTO2, DPTO3, etc but with
> DPTO111, DPTO100 is good. with #px all is true for both DPTO222
> or DPTO12. How filter this range correctly. Thanks.
>
>
> (define dpto "DPTO2") ; legal values are from DPTO1 to DPTO99
> (if (regexp-match? #rx"DPTO[1-9]{1,2}" dpto)
> (display "true dpto")
> (display "false dpto"))
>
> --
> 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] [ANN] trivial 0.1

2016-03-02 Thread Benjamin Greenman
Hello Racket Users,

I'm currently extending this library and writing a little essay on its
implementation. The essay would be much improved if I could report on
users-other-than-myself experience.

If you've used trivial and have any numbers or stories about convenience,
reduced LOC, or bugs found, I'd love to hear them!
In exchange I promise a beer or other legal refreshment at the next
Racket-Con :)

Ben


On Tue, Dec 15, 2015 at 10:33 AM, Benjamin Greenman <
benjaminlgreen...@gmail.com> wrote:

> Short answer: I made a package because I wanted to release as soon as
> possible & encourage feedback / new ideas.
>
>
> Longer answer: I don't think there's any reason TR couldn't integrate
> these "smarter" operators (specifically, macros that inspect their
> arguments before calling a core TR function). That's part of why I used the
> colon notation. But they should be opt-in rather than default features
> because the extra analysis fails in potentially-confusing ways.
>
> (let ([n 2]) (ann (-: n n) Zero)) ;; Type error
>
> These operators can also introduce type errors.
>
> (regexp-match #rx"hello" #"world")
>
> ;; Type error, generated by inferring the result type String from the
> regexp pattern
>
> That example is a bug in my implementation, but it shows how easily things
> can go strange. It's also possible that a user type error triggers a series
> of type errors in the expanded code.
>
>
>
> On Tue, Dec 15, 2015 at 9:27 AM, Matthias Felleisen <matth...@ccs.neu.edu>
> wrote:
>
>>
>> On Dec 15, 2015, at 2:14 AM, Alexis King <lexi.lam...@gmail.com> wrote:
>>
>> > This is pretty neat. Without looking too much into the documentation or
>> implementation, could you briefly elaborate on why these changes are in a
>> separate package rather than improvements to TR itself?
>>
>>
>> +1
>>
>>
>> >
>> > At a quick glance, you mention doing some sort of static analysis on
>> arguments in the normal macro expansion phase: is there any practical
>> reason why TR couldn’t export these? Are there any hidden incompatibilities
>> with the core Racket forms? Or is this just a philosophical division,
>> deciding that TR shouldn’t unnecessarily re-implement forms to perform
>> “magic” typechecking?
>> >
>> > Anyway, my curiosity aside, this is a cool idea. I’ll definitely
>> consider playing with this a bit if I can get some free time.
>> >
>> > Alexis
>> >
>> >> On Dec 14, 2015, at 21:40, Benjamin Greenman <
>> benjaminlgreen...@gmail.com> wrote:
>> >>
>> >> Have you or someone you know [1] ever thought:
>> >>
>> >> "Gee, I wish Typed Racket could figure out that ___ has type ___.
>> >> It's pretty obvious to me."
>> >>
>> >> Then the new "trivial" [2] library is here to help. If you're using
>> basic arithmetic (+, -, *, /), format strings, or regexp-match, just add a
>> colon to the end of your favorite operator.
>> >>
>> >> When a strong type really is obvious, you win!
>> >>
>> >> (require trivial/regexp)
>> >> (cond
>> >> [(regexp-match: #rx"f(o*)" "foobar")
>> >>  =>
>> >>  (lambda ([m : (List String String)]) (cadr m))]
>> >> [else
>> >>  "no match"])
>> >>
>> >> Please send bugs & feature requests to the issue tracker [3]. The
>> tracker's also a good place to complain about the choice of the name
>> "trivial" or the colon notation.
>> >>
>> >> [1] https://groups.google.com/forum/#!topic/racket-users/BfA0jsXrioo
>> >> [2] http://pkg-build.racket-lang.org/doc/trivial/index.html
>> >> [3] https://github.com/bennn/trivial/issues
>> >>
>> >>
>> >> ;; --- More Examples
>> >>
>> >> Before:
>> >> (+ 1 (if (= 0 (- 2 2)) 1 "x"))
>> >> ;; expected: Number, given: (U String One)
>> >>
>> >> (printf "hello ~a")
>> >> ;; raises runtime error
>> >>
>> >> (ann (regexp-match "f(o*)" "foobar")
>> >> (U #f (List String String)))
>> >> ;; Type Error, got type
>> >> ;;   (U #f (Pairof String (Listof (U False String
>> >>
>> >>
>> >> After adding (require trivial):
>> >>
>> >> (+ 1 (if (= 0 (-: 2 2)) 1 "x"))
>> >> ;; Success!
>> >>
&g

Re: [racket-users] "Contracts can have significant overhead" but Typed Racket cannot?

2016-02-29 Thread Benjamin Greenman
One more clarification :p

Contracts are always checked at run-time. Each time you call a function
with a contract on it, you need to check the contract.

Typed functions called from typed code are checked at compile-time. They're
both safe and fast at run-time.

The tricky part is when typed and untyped code interacts i.e. you call a
typed function from an untyped script.
When that happens, Typed Racket compiles types into contracts and checks
those at run-time.

On Mon, Feb 29, 2016 at 4:41 PM, Asumu Takikawa  wrote:

> On 2016-02-29 11:01:17 -0800, Nota Poin wrote:
> > I'm not sure what the qualitative distinction is between contracts and
> Typed
> > Racket. They seem like two syntaxes for what mostly amount to the same
> thing.
> >
> > [...]
> >
> > Is it that contracts are more general, not always necessarily contracts
> of
> > functions that operate on types?
>
> Contracts are indeed more general. You can write arbitrarily complex
> checks in
> contracts, like that the given input-port is not closed, or that the number
> that was inputted is a power of 2.
>
> You can't express these properties in Typed Racket's types.
>
> The idea is that a Racket programmer will start hardening their program by
> writing contracts, possibly ones that are stronger checks than types.
>
> Eventually that programmer may want to add types to detect violations
> earlier
> or within a module, and may remove some of those manually-written
> contracts.
> Ideally you could add types *and* keep the contracts you wrote that are
> more
> expressive than the types.
>
> (we don't have that last step yet, but we should in the future)
>
> Cheers,
> Asumu
>
> --
> 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] Nesting structs – I'm confused!

2016-02-23 Thread Benjamin Greenman
Very puzzling! I think you're doing the update correctly:

> (hash-ref (hashtainer-contents (hash-ref (hashtainer-contents
the-hashtainer) 'layer-1)) 'layer-2)
"hello from layer 2"

But here's the trouble:

> (eq? (hashtainer-contents the-hashtainer)
 (hashtainer-contents (hash-ref (hashtainer-contents the-hashtainer)
'layer-1)))
#t

When I print the hashtainer, here's what I see:

(hashtainer #0=(hash 'layer-1 (hashtainer #0#) 'layer-2 "hello from layer
2"))

And I think this is Racket's way of printing cyclic data.



If we could make sure the #:auto-value is evaluated for each new struct
things would be good.
I'm not sure how to do that, but here's a work-around:

(struct hashtainer (contents) #:transparent)

(define (make-hashtainer) (hashtainer (make-hash)))

;;  then use (make-hashtainer) instead.

;;  You can also (provide (rename-out [make-hashtainer hashtainer]))

;;   to other modules


On Wed, Feb 24, 2016 at 12:45 AM, Gavin McGimpsey  wrote:

> I've been puzzling over this all evening – hoping someone can clarify
> what's going on.
>
> Here's a complete minimal example:
> https://gist.github.com/gavinmcgimpsey/05bfe26f039944f23a9c
>
> I think my question is: what's the proper way to update nested data like
> this?
>
> Gavin
>
> --
> 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] Typed Racket

2016-02-20 Thread Benjamin Greenman
Hi Piyush,

Is it viable to use typed racket for production use ?
>

At least 3 people are using Typed Racket in production:
-
https://groups.google.com/forum/#!searchin/racket-users/typed$20racket|sort:date/racket-users/rfM6koVbOS8/JHaHG03cCQAJ
- https://www.youtube.com/watch?v=QoYJfA7cq2I
- https://twitter.com/ID_AA_Carmack/status/695702976745381889



> is it entirely different language ?
>

Nope. Typed Racket's main design goal is to support the features of untyped
Racket. You should be able to convert a #lang racket program to a #lang
typed/racket program only by adding type annotations.

Disclaimer: the type system is very expressive, but doesn't do much type
inference. So may need to write a lot of annotations, for example

(map (lambda ([v : (U 'cats 'dogs Natural)]) ...) '(9 cats 8 dogs))

(for/fold : (U #f Integer)

  ([biggest : (U #f Integer) #f])

  ([i (in-list '(1 2 3 4))])

  (if biggest

(max biggest i)

i))


But we're always trying to improve.



> how much extra speed/performance we achieve compare to plain racket ?
>

You can expect modest runtime improvements if your whole program is written
in Typed Racket. Probably 5-10%, but I've seen 30% for a program that made
lots of vector accesses. Arithmetic can get much faster too. Clicking the
optimization coach button in Dr. Racket will find places where the
optimizer might be able to do more with the types.

(Compile times will be slower, though)


Does it support all open source libs ?
>

You can use any Racket library in Typed Racket if you give a
`require/typed` annotation that matches your use-case:

(require/typed

  [serialize (Any -> Any)]

  [deserialize (Any -> (HashTable Symbol (List Integer)))])


One thing to keep in mind: these type annotations are checked at runtime,
so each call to deserialize will be a little slower to make sure it really
gives a hashtable with the right values inside. The slowdowns can add up in
surprising ways, but we're working on that too.


Hope you'll try Typed Racket. We're happy to answer questions here or on
the #racket IRC channel.

-- 
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] raco pkg install -> connection refused

2016-02-17 Thread Benjamin Greenman
You should be able to install html-parsing now.

On Wed, Feb 17, 2016 at 9:32 AM, Matthew Flatt  wrote:

> A second problem is is that the package catalog is not supposed to
> depend on that machine's uptime. That's a configuration mistake that we
> will fix, too. Unfortunately, I haven't yet found a way to fix it
> before the machine is back up.
>
> At Wed, 17 Feb 2016 14:21:02 +, Sam Tobin-Hochstadt wrote:
> > Yes, one of our machines failed to come back properly after a reboot to
> > address the glibc security issue. We're working on fixing it.
> >
> > Sam
> >
> > On Wed, Feb 17, 2016 at 9:02 AM Brian Adkins 
> wrote:
> >
> > > I'm trying to install the html-parsing package, and I'm getting a
> > > connection refused error. Is this just a transient issue?
> > >
> > > $ raco pkg install html-parsing
> > > Resolving "html-parsing" via
> > > https://download.racket-lang.org/releases/6.4/catalog/
> > > tcp-connect
> > > :
> > > connection failed
> > >   address: mirror.racket-lang.org
> > >   port number: 80
> > >   step: 6
> > >   system error: Connection refused; errno=61
> > >   context...:
> > >/Applications/Racket v6.4/collects/net/http-client.rkt:235:0
> > >/Applications/Racket
> > > v6.4/collects/racket/contract/private/arrow-val-first.rkt:335:3
> > >/Applications/Racket v6.4/collects/net/url.rkt:144:0:
> > > http://getpost-impure-port
> > >/Applications/Racket v6.4/collects/net/url.rkt:251:2:
> redirection-loop
> > >/Applications/Racket
> > > v6.4/collects/racket/contract/private/arrow-val-first.rkt:335:3
> > >/Applications/Racket v6.4/collects/pkg/private/network.rkt:59:3
> > >/Applications/Racket v6.4/collects/pkg/private/catalog.rkt:218:0:
> > > read-from-server
> > >/Applications/Racket v6.4/collects/pkg/private/catalog.rkt:138:9:
> > > for-loop
> > >/Applications/Racket v6.4/collects/pkg/private/catalog.rkt:135:2:
> > > lookup-normally
> > >/Applications/Racket
> > > v6.4/collects/pkg/private/../../racket/private/more-scheme.rkt:261:28
> > >/Applications/Racket v6.4/collects/pkg/private/prefetch.rkt:128:2
> > >/Applications/Racket v6.4/collects/pkg/private/catalog.rkt:132:0:
> > > package-catalog-lookup9
> > >/Applications/Racket v6.4/collects/pkg/private/catalog.rkt:200:0:
> > > package-catalog-lookup-source19
> > >/Applications/Racket v6.4/collects/pkg/private/clone-path.rkt:370:0:
> > > desc->repo8
> > >/Applications/Racket v6.4/collects/pkg/private/clone-path.rkt:64:2:
> > > add-repo-desc35
> > >/Applications/Racket v6.4/collects/pkg/private/clone-path.rkt:45:0:
> > > adjust-to-normalize-repos
> > >
> > > When I try to open http://mirror.racket-lang.org/releases/6.4/catalog/
> > > directly, I get connection refused.
> > >
> > > Thanks,
> > > Brian
> > >
> > > --
> > > 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.
>
> --
> 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] rebinding a macro-introduced identifier from afar?

2016-02-11 Thread Benjamin Greenman
Could you put the dialect values in separate modules and have the
#%module-begin conditionally pick which dialect modules to require?

On Thu, Feb 11, 2016 at 11:18 AM, Matthew Butterick  wrote:

> > Why don't you put the val-id into the module via foo? Why is bar
> supposed to do that?
>
>
> This is part of a larger pattern where I've got a basic `#%module-begin`
> for my #lang that I want to spin out into dialect-specific versions. The
> dialects only vary in certain values.
>
> Sure, I can make a wrapper macro that generates the `#%module-begin`
> macro. That's what I've done in the past. It works. But a) it's unhygienic,
> and I'm trying to learn cleaner habits, and b) I was recently reminded [1]
> that repeated code should be factored out of macros.
>
> But I'm starting to think that the specialness of `#%module-begin` resists
> this kind of hacking.
>
> [1]
> http://docs.racket-lang.org/style/Language_and_Performance.html#%28part._.Macros__.Space_and_.Performance%29
>
>
>
> On Feb 11, 2016, at 7:08 AM, Matthias Felleisen 
> wrote:
>
> >
> > Why don't you put the val-id into the module via foo? Why is bar
> supposed to do that?
> >
> >
> >
> >
> > On Feb 10, 2016, at 7:13 PM, Matthew Butterick  wrote:
> >
>  You really want to parametrize foo over x for such things. (Or use a
> syntax parameter.)
> >>
> >>
> >> Of course, though I see now that my example is perhaps too schematic.
> If I were really adding, I could do this:
> >>
> >> ;;
> >> #lang racket
> >> (require racket/stxparam rackunit)
> >>
> >> (define-syntax-parameter x-param
> >> (λ (stx) (raise-syntax-error (syntax-e stx) "must be parameterized
> first")))
> >>
> >> (define-syntax-rule (foo) (+ x-param x-param))
> >>
> >> (define-syntax bar
> >> (syntax-rules ()
> >>   [(_ val-in)
> >>(let ([val-id val-in])
> >>  (syntax-parameterize ([x-param (make-rename-transformer #'val-id)])
> >>   (foo)))]))
> >>
> >> (check-equal? (bar 42) 84)
> >> ;;
> >>
> >> Wonderful. But in fact, both my `foo` and `bar` are #%module-begin
> transformers. So I can try to follow the same pattern, but I get stuck at
> the end:
> >>
> >> ;;
> >> #lang racket
> >> (require racket/stxparam)
> >>
> >> (define-syntax-parameter x-param
> >> (λ (stx) (raise-syntax-error (syntax-e stx) "must be parameterized
> first")))
> >>
> >> (define-syntax-rule (foo expr ...) (#%module-begin x-param expr ...))
> >>
> >> (define-syntax bar
> >> (syntax-rules ()
> >>   [(_ val-in)
> >>(let ([val-id val-in])
> >>  (syntax-parameterize ([x-param (make-rename-transformer #'val-id)])
> >>   ))]))
> >> ;;
> >>
> >> If I put `(foo)` on the last line, I'm trying to `syntax-parameterize`
> over a module-begin context, which fails.
> >>
> >> AFAICT it's also not possible to syntax-parameterize over
> `make-rename-transformer`, because it produces a transformer inside a
> transformer, and I'm not clear how to unwrap this so that `bar` is a usable
> #%module-begin macro:
> >>
> >> ;;
> >> #lang racket
> >> (require racket/stxparam)
> >>
> >> (define-syntax-parameter x-param
> >> (λ (stx) (raise-syntax-error (syntax-e stx) "must be parameterized
> first")))
> >>
> >> (define-syntax-rule (foo expr ...) (#%module-begin x-param expr ...))
> >>
> >> (define-syntax bar
> >> (
> >>(λ(stx)
> >>  #'(let ([val-id 42])
> >>  (syntax-parameterize ([x-param (make-rename-transformer
> #'val-id)])
> >>   (make-rename-transformer #'foo))
> >> ;;
> >>
> >>
> >>
> >> On Feb 10, 2016, at 2:52 PM, Matthias Felleisen 
> wrote:
> >>
> >>>
> >>> You really want to parametrize foo over x for such things. (Or use a
> syntax parameter.)
> >>>
> >>>
> >>> On Feb 10, 2016, at 3:26 PM, Matthew Butterick  wrote:
> >>>
>  I suspect there's a simple way to do this, I just haven't done it
> before, so it does not appear simple. I tried a syntax parameter, and then
> I had two problems.
> 
>  Please consider this schematic example (no, I am not using macros to
> add):
> 
>  #lang racket
>  (define-syntax-rule (foo) (+ x x))
>  (define-syntax bar (make-rename-transformer #'foo))
> 
>  `(foo)` will fail with an undefined-identifier error because there is
> no binding for x. As will `(bar)`, because it just refers to `(foo)`.
> 
>  Q: At the definition site of `bar`, is there a way to bind x so that
> it affects `foo`, and `(bar)` thereby produces a meaningful answer?
> 
>
> --
> 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 

Re: [racket-users] rebinding a macro-introduced identifier from afar?

2016-02-11 Thread Benjamin Greenman
Generic path sounds good. When I sent the first message I didn't think
through how to set the flags for #%module-begin, but I'd definitely use a
config file with a generic path (unless there's a way to set compile-time
parameters from the command line).

On Thu, Feb 11, 2016 at 1:22 PM, Matthew Butterick <m...@mbtype.com> wrote:

> I like your idea, but unless I misunderstand, I'd still end up with a
> value (namely the module-picking condition) that I have to influence from
> afar (to produce different results when the #%module-begin runs).
>
> But it suggests another idea, which is to have the #%module-begin load a
> generic relative path, e.g. `(require "dialect-settings.rkt")`. And then
> set up different directories for each dialect with a separate
> "dialect-settings.rkt", so that #%module-begin can be instantiated inside a
> different filesystem context, and thereby coerced into loading the right
> "dialect-settings.rkt".
>
> OTOH the dissertation committee won't be impressed.
>
>
> On Feb 11, 2016, at 9:47 AM, Benjamin Greenman <
> benjaminlgreen...@gmail.com> wrote:
>
> Could you put the dialect values in separate modules and have the
> #%module-begin conditionally pick which dialect modules to require?
>
> On Thu, Feb 11, 2016 at 11:18 AM, Matthew Butterick <m...@mbtype.com> wrote:
>
>> > Why don't you put the val-id into the module via foo? Why is bar
>> supposed to do that?
>>
>>
>> This is part of a larger pattern where I've got a basic `#%module-begin`
>> for my #lang that I want to spin out into dialect-specific versions. The
>> dialects only vary in certain values.
>>
>> Sure, I can make a wrapper macro that generates the `#%module-begin`
>> macro. That's what I've done in the past. It works. But a) it's unhygienic,
>> and I'm trying to learn cleaner habits, and b) I was recently reminded [1]
>> that repeated code should be factored out of macros.
>>
>> But I'm starting to think that the specialness of `#%module-begin`
>> resists this kind of hacking.
>>
>> [1]
>> http://docs.racket-lang.org/style/Language_and_Performance.html#%28part._.Macros__.Space_and_.Performance%29
>>
>>
>>
>> On Feb 11, 2016, at 7:08 AM, Matthias Felleisen <matth...@ccs.neu.edu>
>> wrote:
>>
>> >
>> > Why don't you put the val-id into the module via foo? Why is bar
>> supposed to do that?
>> >
>> >
>> >
>> >
>> > On Feb 10, 2016, at 7:13 PM, Matthew Butterick <m...@mbtype.com> wrote:
>> >
>> >>>> You really want to parametrize foo over x for such things. (Or use a
>> syntax parameter.)
>> >>
>> >>
>> >> Of course, though I see now that my example is perhaps too schematic.
>> If I were really adding, I could do this:
>> >>
>> >> ;;
>> >> #lang racket
>> >> (require racket/stxparam rackunit)
>> >>
>> >> (define-syntax-parameter x-param
>> >> (λ (stx) (raise-syntax-error (syntax-e stx) "must be parameterized
>> first")))
>> >>
>> >> (define-syntax-rule (foo) (+ x-param x-param))
>> >>
>> >> (define-syntax bar
>> >> (syntax-rules ()
>> >>   [(_ val-in)
>> >>(let ([val-id val-in])
>> >>  (syntax-parameterize ([x-param (make-rename-transformer
>> #'val-id)])
>> >>   (foo)))]))
>> >>
>> >> (check-equal? (bar 42) 84)
>> >> ;;
>> >>
>> >> Wonderful. But in fact, both my `foo` and `bar` are #%module-begin
>> transformers. So I can try to follow the same pattern, but I get stuck at
>> the end:
>> >>
>> >> ;;
>> >> #lang racket
>> >> (require racket/stxparam)
>> >>
>> >> (define-syntax-parameter x-param
>> >> (λ (stx) (raise-syntax-error (syntax-e stx) "must be parameterized
>> first")))
>> >>
>> >> (define-syntax-rule (foo expr ...) (#%module-begin x-param expr ...))
>> >>
>> >> (define-syntax bar
>> >> (syntax-rules ()
>> >>   [(_ val-in)
>> >>(let ([val-id val-in])
>> >>  (syntax-parameterize ([x-param (make-rename-transformer
>> #'val-id)])
>> >>   ))]))
>> >> ;;
>> >>
>> >> If I put `(foo)` on the last line, I'm trying to `syntax-parameterize`
>> over a m

Re: [racket-users] Package documentation category with info.rkt

2016-02-09 Thread Benjamin Greenman
Yep, use a string instead of a symbol:

(define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"

The only valid symbols are the category names listed here [1].

[1] http://docs.racket-lang.org/raco/setup-info.html?q=info

On Tue, Feb 9, 2016 at 2:39 AM, Erik Silkensen 
wrote:

> Hi Racket users,
>
> I'm wondering how to control the documentation category for user-defined
> packages?  For example, I've created a YAML package and would like it to
> show up under "Parsing Libraries".  I tried setting
>
> (define scribblings '(("yaml/yaml.scrbl" () (parsing-library
>
> in info.rkt, but after installing the package the link is under
> "Miscellaneous Libraries".
>
> Is there a way to do this?
>
>
> Cheers,
>
> Erik
>
> --
> 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] Package documentation category with info.rkt

2016-02-09 Thread Benjamin Greenman
Hm. I'm not sure what's going on.

If I make a package with your info file, I get no links in the docs. But
changing the collection to "yaml" generates documentation under the
"Parsing Libraries" category.

Can you use "yaml" instead of 'multi ?

On Tue, Feb 9, 2016 at 3:33 AM, Erik Silkensen <eriksilken...@gmail.com>
wrote:

> Thanks, Ben.  I think I’m still missing something, still get the same
> result.  In case it helps, here’s my complete info.rkt:
>
> #lang info
>
> (define collection 'multi)
> (define deps '("base" "srfi-lite-lib" "typed-racket-lib"))
> (define build-deps '("rackunit-lib" "scribble-lib" "racket-doc"
> "sandbox-lib"))
> (define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"
>
> On Feb 9, 2016, at 1:03 AM, Benjamin Greenman <benjaminlgreen...@gmail.com>
> wrote:
>
> Yep, use a string instead of a symbol:
>
> (define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"
>
> The only valid symbols are the category names listed here [1].
>
> [1] http://docs.racket-lang.org/raco/setup-info.html?q=info
>
> On Tue, Feb 9, 2016 at 2:39 AM, Erik Silkensen <eriksilken...@gmail.com>
> wrote:
>
>> Hi Racket users,
>>
>> I'm wondering how to control the documentation category for user-defined
>> packages?  For example, I've created a YAML package and would like it to
>> show up under "Parsing Libraries".  I tried setting
>>
>> (define scribblings '(("yaml/yaml.scrbl" () (parsing-library
>>
>> in info.rkt, but after installing the package the link is under
>> "Miscellaneous Libraries".
>>
>> Is there a way to do this?
>>
>>
>> Cheers,
>>
>> Erik
>>
>> --
>> 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] Help trying to create a script to launch a program from command line.

2016-02-05 Thread Benjamin Greenman
I think you want: (system "~users/myuser/minecraft/start.sh")

-- 
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] scribble: module->typed-exports ?

2016-02-01 Thread Benjamin Greenman
Is there a way to get a list of identifiers exported by a typed module,
along with their type signatures? This is just for scribble, in case that
makes it easier.


The story:

I have an untyped library with a typed compatibility interface, so you can
either (require my-lib) or (require my-lib/typed) depending on whether you
want typed or untyped identifiers. That's all great.

But I'd like to generate scribble for the typed interface automatically --
collect a list of identifiers from my-lib/typed, and link to the untyped
definitions in scribble. (This is important because not all untyped
identifiers have typed counterparts.)
Ideally this list should include types:

f1 : (-> Natural Natural)

v  : Natural

So far I've only got identifiers (via module->exports). Here's what it
looks like:
https://github.com/bennn/zordoz/pull/93

-- 
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] Re: appending files

2016-01-30 Thread Benjamin Greenman
Fixed, thanks for the report!

On Sat, Jan 30, 2016 at 8:31 PM, Scotty C  wrote:

> just found a small mistake in the documentation: can you find it?
>
> (numerator q) → integer?
>
>   q : rational?
>
> Coerces q to an exact number, finds the numerator of the number expressed
> in its simplest fractional form, and returns this number coerced to the
> exactness of q.
>
> (denominator q) → integer?
>
>   q : rational?
>
> Coerces q to an exact number, finds the numerator of the number expressed
> in its simplest fractional form, and returns this number coerced to the
> exactness of q.
>
> --
> 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] Re: LaTeX inspired key bindings

2016-01-28 Thread Benjamin Greenman
On Thu, Jan 28, 2016 at 5:33 PM, Brian Adkins  wrote:

> configure Emacs (like I already have) to display λ instead of lambda


I really like using the agda input mode in Emacs.
http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Docs.UnicodeInput

-- 
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] list of macro & #lang resources

2016-01-27 Thread Benjamin Greenman
The Racket Manifesto
http://www.ccs.neu.edu/home/matthias/manifesto/

On Wed, Jan 27, 2016 at 11:31 AM, Matthew Butterick  wrote:

> For an upcoming project I'm assembling a list of articles & videos about
> making macros and #langs in Racket. These are the ones I've come across,
> but I welcome suggestions of others I've missed.
>
> Culpepper & Alvis: Basic Macrology
> http://rmculpepper.github.io/malr/basic.html
>
> Felleisen: Racket Is ...
> http://www.ccs.neu.edu/home/matthias/Thoughts/Racket_is.html
>
> Flatt: DSL Embedding
> https://www.youtube.com/watch?v=WQGh_NemRy4
>
> Flatt: Creating Languages in Racket
> http://delivery.acm.org/10.1145/207/2063195/p48-flatt.pdf
>
> Flatt: Building Languages in Racket
> https://www.youtube.com/watch?v=y1rOWZkALto
>
> Flatt: Macros, Modules, and Languages
> https://www.youtube.com/watch?v=Z4qn9NFfb9s
>
> Hendershott: Fear of Macros
> http://www.greghendershott.com/fear-of-macros/
>
> Yoo: Fudging Up a Racket
> http://www.hashcollision.org/brainfudge/
>
> --
> 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] appending files

2016-01-26 Thread Benjamin Greenman
On Tue, Jan 26, 2016 at 1:32 AM, Neil Van Dyke  wrote:

> you want to do "filename globbing"



There's also the glob package [1], which should give the exact same API as
the shell. No need to remember the trailing "$" or specifically exclude
dotfiles.

(require glob)
(glob "foo/*/*.rkt")

[1] http://pkgs.racket-lang.org/#[glob]

-- 
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] appending files

2016-01-25 Thread Benjamin Greenman
If you don't mind all the indentation, this one is streaming.

(define (concat file* destination)
  (with-output-to-file destination #:exists 'append
(lambda ()
  ;; 'cat' each file
  (for ([f (in-list file*)])
(with-input-from-file f
  (lambda ()
(for ([ln (in-lines)])
  (displayln ln

On Tue, Jan 26, 2016 at 12:39 AM, Scotty C  wrote:

> here's what i'm doing. i make a large, say 1 gb file with small records
> and there is some redundancy in the records. i will use a hash to identify
> duplicates by reading the file back in a record at a time but the file is
> too large to hash so i split it. the resultant files (10) are about 100 mb
> and are easily hashed. the resultant files need to be appended and then
> renamed back to the original. i know that i can do this in a linux terminal
> window with the following: cat mytmp*.dat >> myoriginal.dat. i'd like to
> accomplish this from within the program by shelling out. can't figure it
> out. other methodologies that are super fast will be entertained. thanks,
> scott
>
> --
> 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] warning on use trie functions in #lang racket?

2016-01-05 Thread Benjamin Greenman
I'm afraid it's just O(n) contracts. For example:

#lang racket/base

(module stack typed/racket/base
  (define-type Stack (Listof Integer))
  (provide:
[create (-> Stack)]
[push (-> Integer Stack Stack)]
[pop  (-> Stack Stack)])

  (define (create) '())
  (define push cons)
  (define pop cdr))

(require 'stack contract-profile)

(define (test)
  (for/fold ([st (create)])
([i (in-range 5000)])
(push i st))
  (void))

(contract-profile (time (test)))
;; Running time is 80.46% contracts
;; 70/87 ms




On Tue, Jan 5, 2016 at 3:19 PM, Vincent St-Amour <
stamo...@eecs.northwestern.edu> wrote:

> (add1 Jay)
>
> That kind of overhead has to be a bug somewhere, or a bad way to write
> something. I hope.
>
> Vincent
>
>
>
> On Tue, 05 Jan 2016 13:40:33 -0600,
> Jay McCarthy wrote:
> >
> > I would prefer taking this useful library and making it actually
> > useful to all Racket users.
> >
> > Jay
> >
> > On Tue, Jan 5, 2016 at 2:39 PM, 'John Clements' via Racket Users
> >  wrote:
> > > Asumu, does this make sense to you? Note that in particular, I think
> that a warning at the top of the pfds package wouldn’t have helped me; I
> think a warning at the top of each pfds page would make a lot more sense.
> > >
> > > John
> > >
> > >> On Jan 5, 2016, at 11:00 AM, Sam Tobin-Hochstadt <
> sa...@cs.indiana.edu> wrote:
> > >>
> > >> Yes, I think a warning at the top of the documentation for the `pfds`
> package would make sense, and probably Asumu would accept such a pull
> request. You might follow the phrasing in the math/array library.
> > >>
> > >> Sam
> > >>
> > >> On Tue, Jan 5, 2016 at 1:49 PM 'John Clements' via Racket Users <
> racket-users@googlegroups.com> wrote:
> > >> This program constructs a trie containing exactly two keys; each is a
> list of 256 integers. On my machine, it takes *twelve seconds*. The time
> taken appears to be n^2 in the length of the key, so doubling it to 256
> means it’ll take about a minute to add a key.
> > >>
> > >> #lang racket
> > >>
> > >> (require pfds/trie)
> > >>
> > >> (define (rand-list)
> > >>   (for/list ([i (in-range 128)])
> > >> (random 256)))
> > >>
> > >> (define t (trie (list (rand-list
> > >> (define u (time (bind (rand-list) 0 t)))
> > >>
> > >> When I translate this to typed racket, the time taken is 0 ms.
> > >>
> > >> I feel like I got a bit burned here, and an ordinary user might
> simply conclude that Racket libraries are teh suck.
> > >>
> > >> Can we add a warning to the beginning of the documentation page for
> Tries (and perhaps for the other data structures as well) indicating that
> these functions are likely to be unusably slow in #lang racket?
> > >>
> > >> I propose the following, at the top of the documentation. Possibly in
> boldface.
> > >>
> > >> “NB: these data structures are written in Typed Racket. While they
> may be nominally usable in the (untyped) Racket language, the resulting
> dynamic checks will probably cause them to be unacceptably slow”
> > >>
> > >> Suggestions? May I make a pull request here?
> > >>
> > >> John
> > >>
> > >>
> > >>
> > >> --
> > >> 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.
> >
> >
> >
> > --
> > Jay McCarthy
> > Associate Professor
> > PLT @ CS @ UMass Lowell
> > http://jeapostrophe.github.io
> >
> >"Wherefore, be not weary in well-doing,
> >   for ye are laying the foundation of a great work.
> > And out of small things proceedeth that which is great."
> >   - D 64:33
> >
> > --
> > 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.
>

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

Re: [racket-users] warning on use trie functions in #lang racket?

2016-01-05 Thread Benjamin Greenman
Right, my comment was intended to show that innocent Typed Racket libraries
may be harmful to Racket programmers.

On Tue, Jan 5, 2016 at 3:30 PM, Jay McCarthy <jay.mccar...@gmail.com> wrote:

> Your comment is not evidence that Typed Racket libraries are useful to
> Racket programmers, but in fact the opposite.
>
> Jay
>
> On Tue, Jan 5, 2016 at 3:28 PM, Benjamin Greenman
> <benjaminlgreen...@gmail.com> wrote:
> > I'm afraid it's just O(n) contracts. For example:
> >
> > #lang racket/base
> >
> > (module stack typed/racket/base
> >   (define-type Stack (Listof Integer))
> >   (provide:
> > [create (-> Stack)]
> > [push (-> Integer Stack Stack)]
> > [pop  (-> Stack Stack)])
> >
> >   (define (create) '())
> >   (define push cons)
> >   (define pop cdr))
> >
> > (require 'stack contract-profile)
> >
> > (define (test)
> >   (for/fold ([st (create)])
> > ([i (in-range 5000)])
> > (push i st))
> >   (void))
> >
> > (contract-profile (time (test)))
> > ;; Running time is 80.46% contracts
> > ;; 70/87 ms
> >
> >
> >
> >
> > On Tue, Jan 5, 2016 at 3:19 PM, Vincent St-Amour
> > <stamo...@eecs.northwestern.edu> wrote:
> >>
> >> (add1 Jay)
> >>
> >> That kind of overhead has to be a bug somewhere, or a bad way to write
> >> something. I hope.
> >>
> >> Vincent
> >>
> >>
> >>
> >> On Tue, 05 Jan 2016 13:40:33 -0600,
> >> Jay McCarthy wrote:
> >> >
> >> > I would prefer taking this useful library and making it actually
> >> > useful to all Racket users.
> >> >
> >> > Jay
> >> >
> >> > On Tue, Jan 5, 2016 at 2:39 PM, 'John Clements' via Racket Users
> >> > <racket-users@googlegroups.com> wrote:
> >> > > Asumu, does this make sense to you? Note that in particular, I think
> >> > > that a warning at the top of the pfds package wouldn’t have helped
> me; I
> >> > > think a warning at the top of each pfds page would make a lot more
> sense.
> >> > >
> >> > > John
> >> > >
> >> > >> On Jan 5, 2016, at 11:00 AM, Sam Tobin-Hochstadt
> >> > >> <sa...@cs.indiana.edu> wrote:
> >> > >>
> >> > >> Yes, I think a warning at the top of the documentation for the
> `pfds`
> >> > >> package would make sense, and probably Asumu would accept such a
> pull
> >> > >> request. You might follow the phrasing in the math/array library.
> >> > >>
> >> > >> Sam
> >> > >>
> >> > >> On Tue, Jan 5, 2016 at 1:49 PM 'John Clements' via Racket Users
> >> > >> <racket-users@googlegroups.com> wrote:
> >> > >> This program constructs a trie containing exactly two keys; each
> is a
> >> > >> list of 256 integers. On my machine, it takes *twelve seconds*.
> The time
> >> > >> taken appears to be n^2 in the length of the key, so doubling it
> to 256
> >> > >> means it’ll take about a minute to add a key.
> >> > >>
> >> > >> #lang racket
> >> > >>
> >> > >> (require pfds/trie)
> >> > >>
> >> > >> (define (rand-list)
> >> > >>   (for/list ([i (in-range 128)])
> >> > >> (random 256)))
> >> > >>
> >> > >> (define t (trie (list (rand-list
> >> > >> (define u (time (bind (rand-list) 0 t)))
> >> > >>
> >> > >> When I translate this to typed racket, the time taken is 0 ms.
> >> > >>
> >> > >> I feel like I got a bit burned here, and an ordinary user might
> >> > >> simply conclude that Racket libraries are teh suck.
> >> > >>
> >> > >> Can we add a warning to the beginning of the documentation page for
> >> > >> Tries (and perhaps for the other data structures as well)
> indicating that
> >> > >> these functions are likely to be unusably slow in #lang racket?
> >> > >>
> >> > >> I propose the following, at the top of the documentation. Possibly
> in
> >> > >> boldface.
> >> > >>
> >> > >> “NB: these data structures are written in Typed Racket. While th

Re: [racket-users] Potential Contract Profiler UI Change

2016-01-05 Thread Benjamin Greenman
Sounds great! Two suggestions:

1. A `raco contract-profile` command to run the main submodule in a file.

2. Make even less output by default -- just the overall runtime & by-callee
contracts.

But this is just my opinion :)


On Tue, Jan 5, 2016 at 6:06 PM, Vincent St-Amour <
stamo...@eecs.northwestern.edu> wrote:

>
> I'm considering a change to the UI of the contract profiler, and would
> like opinions from people using it.
>
> As of 6.3, the contract profiler emits its various reports in a few
> separate files, whose names are hard-coded. This is (IMO) a UI
> disaster, which makes the profiler harder to use.
>
> As of HEAD, the situation is slightly better; file names can be
> specified, individual reports can be enabled/disabled, and the main
> report (the cost breakdown) has the option to be produced on standard
> output (as the regular Racket profiler does). This change was fully
> backwards compatible, but still does not result in a great UI. This
> change has also not been part of a release yet.
>
>
> For the next release, I'm considering redesigning this part of the
> contract profiler UI. Specifically, I'm proposing:
>
>   - Emitting the cost breakdown on standard output, like the regular
> Racket profiler.
>   - Disabling alternative views (module view and boundary view) by
> default.
>   - Allow enabling alternative views individually, and specifying their
> output files.
>   - Disabling output of intermediate graphviz files by default, even
> when alternative views are enabled, with the option to enable them.
>
> As a result, the contract profiler would not produce any output files
> unless it's explicitly asked to, and instead emit its main output to
> standard output. All the existing reports would still be available, but
> some would not be shown by default, emphasizing the most-often-useful
> one.
>
>
> I think this change would make the contract profiler easier and faster
> to use, especially for quick tests.
>
> This change, however, is not fully backwards compatible. Mind you, it is
> a UI change; the API to the contract profiler remains unchanged. But if
> you have scripts that depend on the location of the profiler's output,
> they would need to change.
>
>
> Any opinions?
>
> I'd like to make this change before the release, so timely replies would
> be appreciated. :)
>
> Vincent
>
> --
> 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] Typed/Untyped cost reduction and experience

2015-12-29 Thread Benjamin Greenman
Is the server code online anywhere? I'd like to see what the boundary
contracts are.

Let me know if starting typed works for a future project. So far, I've had
the best experience starting untyped but keeping type annotations in
comments -- basically like no-check, but without annotations on lambdas or
for loops. The worst times I've had were hitting "dead-ends" while
converting because I didn't understand Typed Racket, but after a little
more experience it's nice to wait until the program works to enforce the
types & catch edge cases.

On Sat, Dec 26, 2015 at 6:52 PM, JCG  wrote:

> Having just converted a server process of about 1800 lines of untyped
> Racket to 1900 lines of typed Racket, I'd like to make some comments
>
> 1) I highly suggest starting in Typed Racket if you are going to go end up
> there.  I made the mistake of writing it untyped and then retrofitting
> which clearly is the more difficult path.
>
> 2) The conversion caught one likely-to-happen-sometime bug, thank you.
>
> 3) The end-product appears to be a 50%-performance hybrid due to boundary
> contracts,  but ameliorated runtime-wise by utilizing the
> typed/racket/no-check language after it's all working in type checked mode.
>
> 4) I failed to create a valid new language with conditional inclusion of
> typed and no-check variants, but a command line or in-program conditional
> ability to disable types would permit an easy to accept morphing systems
> which need to gently attain 100% typed nature.   At the moment, I use a
> Unix shell script to doctor the #lang lines.  For instance 'raco -no-check
> exe ...' would really be nice after concluding that my slow hybrid is
> operating correctly.
>
> 5) When retrofitting, Dr Racket nicely points out errors, which in
> quantity should perhaps be limited to speed the retrofit cycle.  Being
> familiar with G++ template errors, I was not too shocked.  One thing that I
> learned was instead of attacking the first error which often was deeper in
> a function, it was more profitable to start at the outside, i.e. the
> function signature, and allow that information to imply further
> information.   I found that otherwise, I ended up with correct but
> superfluous annotations.
>
> 6) A few missing typed versions of libraries were what caused me to not
> start there, notably the lack of typed/db.
>
> Thanks,
> JG
>
> --
> 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] Typed/Untyped cost reduction and experience

2015-12-29 Thread Benjamin Greenman
On Tue, Dec 29, 2015 at 7:05 PM, JCG  wrote:

> If I understand this correctly, the unsafe version will perform the same
> static checks on callers of the functions published by (provide) but not
> incur contract cost.


Yep, that's right.

#lang typed/racket/base
(require typed/racket/unsafe)
(unsafe-require/typed racket/base (values (-> String Integer)))

(string-append (values "foo") "bar")  ;; Type Error
(+ (values "foo") 1)  ;; Runtime Error, because annotation on `values` is
incorrect

-- 
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] Time Series in Racket

2015-12-28 Thread Benjamin Greenman
On Mon, Dec 28, 2015 at 5:29 AM, Greg Trzeciak  wrote:

> Re: 3 Is there any example of plotting with x axis being the time+date
> available?


There's a small example in the docs for the 'plot' package:
http://docs.racket-lang.org/plot/ticks_and_transforms.html#%28def._%28%28lib._plot%2Fmain..rkt%29._ticks-scale%29%29

Documentation on time ticks is here:
http://docs.racket-lang.org/plot/ticks_and_transforms.html#%28part._.Time_.Ticks%29

And here's a smaller example:

#lang racket/base

(require plot)

(define (earnings ms)
 (let ([d (seconds->date ms)])
   (expt (date-minute d) 2)))

(define (hour->date h)
  (date 0 0 h 1 1 2015 0 0 #f 0))

(parameterize ([plot-x-ticks (time-ticks #:number 6 #:formats '("~Mm"))])
  (plot
(function earnings #:label "$$$")
#:x-min (datetime->real (hour->date 2))
#:x-max (datetime->real (hour->date 3

-- 
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] listing the identifiers from "all-defined-out" and "all-from-out"

2015-12-22 Thread Benjamin Greenman
You might also like `filtered-out` from `racket/provide` [1]. The code
sample below prints two identifiers (at compile-time):

a:x

y


[1]
http://docs.racket-lang.org/reference/require.html#%28mod-path._racket%2Fprovide%29


#lang racket/base

(module a racket/base
  (provide x)
  (define x 1))

(require 'a)
(require racket/provide)
(require (for-syntax racket/base))

(define y 4)

(define-for-syntax (print-provide str)
  (displayln str)
  str)

(provide
  (filtered-out print-provide (prefix-out a: (all-from-out 'a)))
  (filtered-out print-provide (all-defined-out)))

On Tue, Dec 22, 2015 at 5:21 PM, Asumu Takikawa  wrote:

> On 2015-12-18 17:27:54 -0800, Sanjeev Sharma wrote:
> > how can I get lists of identifiers im/exported when one uses
> >
> > all-defined-out
> > all-from-out
> >
> > I can't yet make sense of regprov.rkt
>
> Do you mean how can you tell what's exported given a particular module
> someone
> has written? Or do you mean something more specific?
>
> For the former, you can just call `module->exports` to get a list of
> exports:
>
>   -> (require data/gvector)
>   -> (module->exports 'data/gvector)
>   '()
>   '((0
>  (for*/gvector ())
>  (for/gvector ())
>  (gvector ())
>  (gvector->list ())
>  (gvector->vector ())
>  (gvector-add! ())
>  (gvector-count ())
>  (gvector-ref ())
>  (gvector-remove! ())
>  (gvector-remove-last! ())
>  (gvector-set! ())
>  (gvector? ())
>  (in-gvector ())
>  (make-gvector (
>
> Cheers,
> Asumu
>
> --
> 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] [newbie] Help with streams

2015-12-20 Thread Benjamin Greenman
I've been struggling with streams recently too. in-producer

solved
my problems.

(define name-gen
  (in-producer (lambda () (new-name ethnicity sex

(define some-names
  (for/list ([name name-gen] [i (in-range 10)]) name))

On Sun, Dec 20, 2015 at 9:48 PM, mark  wrote:

>
> Hi, there.  I have just started playing with Racket and would like some
> help with using streams/generators (I am not particularly versed in
> programming in a functional style and am attempting to learn :-))
>
> So I have a function called (new-name) that creates a random name, like
> "Bob Brown" or "Jill Xi".  It looks something like
>
>  (define (new-name ethnicity sex)
>   ; return a string like "First LAST" based on ethnicity and sex)
>
> This is all good and dandy and works well.  What I would like to do now is
> something like
>
>   (define name-gen
> (infinite-generator
>(yield (new-name ethnicity sex  ; won't work...
>
>   (get-some-names (name-gen "anglo" "male") 10) ; not sure about this...
>
> Which would, from a generated list or stream, return ten names.  I can do
> this using something like
>
>  (for/list ([i 10])
>(new-name "anglo" "male"))
>
> but that seems to miss out on the goodness of streams/generators.
>
> Any help/tips appreciated.
>
> TIA, .. mark.
>
> --
> 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] Advent of Code

2015-12-19 Thread Benjamin Greenman
Here's how I'd outline lang/reader.rkt, assuming the API from
advent7/main.rkt in comments below.
(If I write a full solution, I'll come back & post that)


#lang racket/base

(provide (rename-out
  [advent7-read read]
  [advent7-read-syntax read-syntax]))

(require  racket/port
  syntax/strip-context  (only-in advent7 ;; ASSUMPTION:   parse-line
;; (-> String Gate)   solve   ;; (-> (Listof Gate) Solution)))
;; =

(define (advent7-read in)
  (syntax->datum (advent7-read-syntax #f in)))

(define (advent7-read-syntax src-path in)
  (let* ([gate* (map parse-line (port->lines in))] [sol (solve
gate*)])(strip-context #`(module advent7-program racket/base
  (define input #,gate*) (define solution '#,sol)
(printf "Input:\n~a\n\nSolution:\n~a\n" input solution)


On Sat, Dec 19, 2015 at 6:01 AM, Daniel Prager 
wrote:

> I'm having a bit of fun working through the puzzles on adventofcode.com using
> Racket, and of course trying to use it to improve my Racket skills along
> the way.
>
> I've just solved Day 7 (adventofcode.com/day/7) for which the input
> "data" starts with:
>
> lf AND lq -> ls
>> iu RSHIFT 1 -> jn
>> bo OR bu -> bv
>> gj RSHIFT 1 -> hc
>> et RSHIFT 2 -> eu
>> bv AND bx -> by
>> is OR it -> iu
>> b OR n -> o
>
>
> and continues for a few hundred lines, ostensibly describing a system of
> wires and logic gates.
>
> Could this make a good example of how to make a one-off #lang in order to
> write a single program?
>
> I didn't make a #lang, but I'd love to see a solution that turns the data
> into input for #lang advent-day-7 (or whatever).
>
> Any takers?
>
> Dan
>
>
> --
> 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] [ANN] trivial 0.1

2015-12-15 Thread Benjamin Greenman
Short answer: I made a package because I wanted to release as soon as
possible & encourage feedback / new ideas.


Longer answer: I don't think there's any reason TR couldn't integrate these
"smarter" operators (specifically, macros that inspect their arguments
before calling a core TR function). That's part of why I used the colon
notation. But they should be opt-in rather than default features because
the extra analysis fails in potentially-confusing ways.

(let ([n 2]) (ann (-: n n) Zero)) ;; Type error

These operators can also introduce type errors.

(regexp-match #rx"hello" #"world")

;; Type error, generated by inferring the result type String from the
regexp pattern

That example is a bug in my implementation, but it shows how easily things
can go strange. It's also possible that a user type error triggers a series
of type errors in the expanded code.



On Tue, Dec 15, 2015 at 9:27 AM, Matthias Felleisen <matth...@ccs.neu.edu>
wrote:

>
> On Dec 15, 2015, at 2:14 AM, Alexis King <lexi.lam...@gmail.com> wrote:
>
> > This is pretty neat. Without looking too much into the documentation or
> implementation, could you briefly elaborate on why these changes are in a
> separate package rather than improvements to TR itself?
>
>
> +1
>
>
> >
> > At a quick glance, you mention doing some sort of static analysis on
> arguments in the normal macro expansion phase: is there any practical
> reason why TR couldn’t export these? Are there any hidden incompatibilities
> with the core Racket forms? Or is this just a philosophical division,
> deciding that TR shouldn’t unnecessarily re-implement forms to perform
> “magic” typechecking?
> >
> > Anyway, my curiosity aside, this is a cool idea. I’ll definitely
> consider playing with this a bit if I can get some free time.
> >
> > Alexis
> >
> >> On Dec 14, 2015, at 21:40, Benjamin Greenman <
> benjaminlgreen...@gmail.com> wrote:
> >>
> >> Have you or someone you know [1] ever thought:
> >>
> >> "Gee, I wish Typed Racket could figure out that ___ has type ___.
> >> It's pretty obvious to me."
> >>
> >> Then the new "trivial" [2] library is here to help. If you're using
> basic arithmetic (+, -, *, /), format strings, or regexp-match, just add a
> colon to the end of your favorite operator.
> >>
> >> When a strong type really is obvious, you win!
> >>
> >> (require trivial/regexp)
> >> (cond
> >> [(regexp-match: #rx"f(o*)" "foobar")
> >>  =>
> >>  (lambda ([m : (List String String)]) (cadr m))]
> >> [else
> >>  "no match"])
> >>
> >> Please send bugs & feature requests to the issue tracker [3]. The
> tracker's also a good place to complain about the choice of the name
> "trivial" or the colon notation.
> >>
> >> [1] https://groups.google.com/forum/#!topic/racket-users/BfA0jsXrioo
> >> [2] http://pkg-build.racket-lang.org/doc/trivial/index.html
> >> [3] https://github.com/bennn/trivial/issues
> >>
> >>
> >> ;; --- More Examples
> >>
> >> Before:
> >> (+ 1 (if (= 0 (- 2 2)) 1 "x"))
> >> ;; expected: Number, given: (U String One)
> >>
> >> (printf "hello ~a")
> >> ;; raises runtime error
> >>
> >> (ann (regexp-match "f(o*)" "foobar")
> >> (U #f (List String String)))
> >> ;; Type Error, got type
> >> ;;   (U #f (Pairof String (Listof (U False String
> >>
> >>
> >> After adding (require trivial):
> >>
> >> (+ 1 (if (= 0 (-: 2 2)) 1 "x"))
> >> ;; Success!
> >>
> >> (printf: "hello ~a")
> >> ;; Compile-time error
> >>
> >> (ann (regexp-match "f(o*)" "foobar")
> >> (U #f (List String String)))
> >> ;; Success!
> >>
> >>
> >> If a strong type isn't clear from the call site, you get standard Typed
> Racket types.
> >>
> >> (let ([n 2]) (-: n 2))
> >> ;; Type: Integer
> >>
> >> ((lambda ([f : (-> String Void)]) (f "~b" 'NaN))
> >> printf:)
> >> ;; Runtime error
> >>
> >> (regexp-match: "f(o*)|bar" "foo")
> >> ;; Type: (U #f (Pairof String (Listof (U #f String
> >>
> >>
> >> One more thing: there's a special form for compiling regular expression
> patterns:
> >>
> >> (define-regexp: my-pat #rx"f

[racket-users] [ANN] trivial 0.1

2015-12-14 Thread Benjamin Greenman
Have you or someone you know [1] ever thought:

"Gee, I wish Typed Racket could figure out that ___ has type ___.
It's pretty obvious to me."


Then the new "trivial" [2] library is here to help. If you're using basic
arithmetic (+, -, *, /), format strings, or regexp-match, just add a colon
to the end of your favorite operator.

When a strong type really is obvious, you win!

(require trivial/regexp)

(cond

 [(regexp-match: #rx"f(o*)" "foobar")
  =>
  (lambda ([m : (List String String)]) (cadr m))]
 [else
  "no match"])


Please send bugs & feature requests to the issue tracker [3]. The tracker's
also a good place to complain about the choice of the name "trivial" or the
colon notation.

[1] https://groups.google.com/forum/#!topic/racket-users/BfA0jsXrioo
[2] http://pkg-build.racket-lang.org/doc/trivial/index.html
[3] https://github.com/bennn/trivial/issues


;; --- More Examples

*Before*:

(+ 1 (if (= 0 (- 2 2)) 1 "x"))
;; expected: Number, given: (U String One)

(printf "hello ~a")
;; raises runtime error

(ann (regexp-match "f(o*)" "foobar")
 (U #f (List String String)))

;; Type Error, got type

;;   (U #f (Pairof String (Listof (U False String



*After* adding (require trivial):

(+ 1 (if (= 0 (-: 2 2)) 1 "x"))
;; Success!

(printf: "hello ~a")
;; Compile-time error

(ann (regexp-match "f(o*)" "foobar")
 (U #f (List String String)))
;; Success!



If a strong type isn't clear from the call site, you get standard Typed
Racket types.

(let ([n 2]) (-: n 2))

;; Type: Integer

((lambda ([f : (-> String Void)]) (f "~b" 'NaN))

 printf:)

;; Runtime error

(regexp-match: "f(o*)|bar" "foo")
;; Type: (U #f (Pairof String (Listof (U #f String



One more thing: there's a special form for compiling regular expression
patterns:

(define-regexp: my-pat #rx"f(o*)")

;; Also supports pregexp, byte-regexp, byte-pregexp

(ann (regexp-match: my-pat "")

 (U #f (List String String)))

;; Success!

-- 
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] Re: Happy Module Day!

2015-12-11 Thread Benjamin Greenman
>
> FWIW, http://www.dwheeler.com/sloccount/ might be a better way to
> accomplish this once it supports Racket detection. I just opened a feature
> request for that at
> https://sourceforge.net/p/sloccount/feature-requests/20/ and am hoping
> there is interest.
>

You could also use sloc [1], which already supports Racket. Or just trust
github's count (47.6% Racket, 34% C at [2])

[1] https://github.com/flosse/sloc
[2] https://github.com/racket/racket

-- 
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] pasteboard% applications

2015-12-01 Thread Benjamin Greenman
I know of two (but I don't know them well)

The PLT card games library:
https://github.com/racket/games/blob/master/cards/classes.rkt

Matthias's Acquire game:
https://github.com/mfelleisen/Acquire/blob/master/tree-game.rkt

On Tue, Dec 1, 2015 at 10:39 PM, Byron Davies 
wrote:

> Does anyone have an application using pasteboard%?  I want to try one, and
> I’d love to see an example.
>
> Byron
> 
> Byron Davies, Ph.D.
> StarShine Academy International Schools
> Revolutionizing children’s learning. Seeking the Global Learning XPRIZE
> http://starshineplanet.com
>
> --
> 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] Value printing in REPL and for students

2015-11-26 Thread Benjamin Greenman
I think you'll want to override the current-print

 parameter.

On Thu, Nov 26, 2015 at 7:16 PM, Paolo Giarrusso 
wrote:

> Hi all!
>
> How does the REPL print values? In some circumstances I see graph printing
> markers, even though `(print-graph)` is disabled. Because these are error
> messages for students using teaching languages, cycle printing is not an
> option.
>
> messages.rkt> (print-graph)
> #f
> messages.rkt> (list (game-state p p p))
> (list (game-state (posn 150 100) (posn 150 100) (posn 150 100)))
> messages.rkt> (~v (list (game-state p p p)))
> "(list (game-state #0=(posn 150 100) #0# #0#))"
>
> Funnily, that doesn't happen in DrRacket, but it does happen both in
> racket-mode, in my actual production environment, and under raco test. In
> particular, test results in DrRacket are the ones I'd want, but are
> inconsistent with the ones everywhere else.
>
> Apart from being frustrated at parameters, how do I gain control over this?
>
> PS: I've just found that `global-port-print-handler` is customized by
> DrRacket. That seems incompatible with using `print` and relying on it
> producing certain results. I understand that's the point of `print`, but
> neither `write` nor `display` does what I want.
>
> HTDP code itself uses `~e` (also in htdp/error), but finding the
> appropriate handler to install isn't trivial either; and that's not enough,
> because sometimes I need to show the source code we evaluated.
>
> Sorry for how chaotic is this message — I guess that reflects my confusion
> at Racket printing. (I've taken some looks at the relevant documentation,
> but not at all of it).
>
> Cheers,
> Paolo
>
> --
> 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] racket users fight for their right to colon keywords

2015-10-14 Thread Benjamin Greenman
On Wed, Oct 14, 2015 at 11:01 PM, Alexis King  wrote:

> I can’t wait until all of my programs look like this at the top:


Haskellers are living the dream. For example:
https://github.com/ekmett/lens/blob/master/src/Control/Lens/Tuple.hs

-- 
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] help on coding finite state automata

2015-10-13 Thread Benjamin Greenman
>
> - why you use [i (in-range 10)] in all for loop? what's the difference
> with [i 10]. they both produce stream, right?


Yes, but `in-range` runs faster because of "types". Here's a little example:

#lang racket/base
(define N (expt 10 7))

(time (for ([n (in-range N)])  (void)))
;; cpu time: 36 real time: 36 gc time: 0

(time (for ([n N])  (void)))
;; cpu time: 635 real time: 635 gc time: 0

-- 
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] module providing both safe and unsafe procedures

2015-09-29 Thread Benjamin Greenman
How about making an unsafe submodule?


#lang racket/base

(provide vplus)

(module+ unsafe
  (provide vplus)
  (require racket/unsafe/ops))

(define (vplus v1 v2)
  (build-vector (vector-length v1)
(lambda (i) (+ (vector-ref v1 i)
   (vector-ref v2 i)

(module+ unsafe
  (define (vplus v1 v2)
(build-vector (unsafe-vector-length v1)
  (lambda (i) (+ (unsafe-vector-ref v1 i)
 (unsafe-vector-ref v2 i))


The require becomes a little ugly, but I guess that's a good warning flag.

#lang racket/base

;(require
;  (only-in "unsafe-submod.rkt" vplus))
(require
  (only-in (submod "unsafe-submod.rkt" unsafe) vplus))

(vplus 0 0) ;; Segfault

On Tue, Sep 29, 2015 at 9:17 AM, Neil Van Dyke  wrote:

> Does it make sense for a non-Racket #lang module to `provide` both *safe*
> and *unsafe* (in the sense of `racket/unsafe/ops`) variants of procedures?
>
> If so, any tricks to doing that?
>
> For example:
> * A function `foo` defined in this #lang module might result in the module
> providing two Racket procedures: `foo` and `foo/unsafe`.
> * `foo/unsafe` might use `racket/unsafe/ops`, but `foo` would not.
> * I want outside Racket code that uses only `foo` (not `foo/unsafe`) from
> this #lang module to not incur any kind of taint.
>
> Neil V.
>
> --
> 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] Question about structuring recursive code

2015-09-23 Thread Benjamin Greenman
Could you post the "ugly" code? I'm curious because things like this
compile fine:

(define (f-recur x y)
 (cond ((< x 1)
10)
  (else
   (define z 3)
   (f-recur x y

On Wed, Sep 23, 2015 at 7:25 PM, Kaushik Ghose 
wrote:

>
> On Wed, Sep 23, 2015 at 12:26 PM, Pierpaolo Bernardi 
>> wrote:
>>
>>> On Wed, Sep 23, 2015 at 6:18 PM, Kaushik Ghose 
>>> wrote:
>>>
>>> > Can I have any statements in this block that I could have in a (define
>>> ...)
>>> > block? Can I have (defines ) for example?
>>>
>>> Yes, and yes  :)
>>>
>>
>> Hmm. I get a "define: not allowed in an expression context" when I try to
> do that. I did manage to use nested let* and let-values to achieve my goal,
> though it looks pretty ugly.
>
> --
> 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] Question about structuring recursive code

2015-09-23 Thread Benjamin Greenman
On Wed, Sep 23, 2015 at 7:38 PM, Kaushik Ghose 
wrote:

> I haven't gotten to cond yet.


Ok. Yeah, if- branches aren't allowed to have definitions, or even
sequences of operations. You can get around this with begin:

(define (f x)
  (if (even? x)
  (/ x 2)
  (begin
(define a (* x 2))
(define b (* x 3))
(f (+ a b)

--

-- 
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] Re: typed/racket + rackunit = trouble

2015-09-17 Thread Benjamin Greenman
On Thu, Sep 17, 2015 at 4:38 PM, Raoul Duke  wrote:

> wait, who needs tests when you have static typing?! sheesh


Really though, Typed Racket might benefit from a non-rackunit library that
encourages a different style of testing.
(Instead of duplicating all the rackunit code.)

-- 
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] Scribble: line comment swallows paragraph break

2015-09-16 Thread Benjamin Greenman
Scribble and LaTeX disagree on these documents. Should Scribble be changed
to match LaTeX?

Scribble:
#lang scribble/manual

Hello @; John

World

Output is:
"Hello World"

;; ---

LaTeX
\documentclass{article}
\begin{document}
Hello % John

World
\end{document}

Output is:
"Hello
World"

-- 
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] values considered harmful

2015-09-12 Thread Benjamin Greenman
Something bad happened. I was using values and pairs, made a small mistake,
and wound up with a segfault (on v6.2 and v6.2.900.16). Here's a minimal
example:

#lang racket/base

(define (split xy)
  (define-values (x y) (values (car xy) (cdr xy)))
  (values y x)) ;; My mistake: x should be a pair

(define-values (a b) (split (cons 0 1)))
(split b)

What's really strange to me is that many versions of this program raise the
expected "car: contract violation" error. For example, try changing the
buggy line to `(values x y)` or `(values x x)` or even `(values (+ y) (+
x))`.

-- 
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] Question about log-ticks

2015-08-28 Thread Benjamin Greenman
I'm not sure if this is intended, but I do have a hack to add them in
manually:

(parameterize ([plot-y-transform log-transform]
   [plot-y-ticks (log-ticks #:number 6)])
 (define xs (range 1 11))
 (define ys (map (lambda (x) (exp x)) xs))
 (define extra-ticks (for/list ([n (in-range 2 10)]) (tick n #f )))
 (plot (list (points (map vector xs ys) #:y-min 1)
 (y-ticks extra-ticks #:far? #t)
 (y-ticks extra-ticks #:far? #f

On Fri, Aug 28, 2015 at 4:06 PM, Marduk Bolaños mardu...@gmail.com wrote:

 Dear all,

 I did a scatter plot with a logarithmic Y-axis. It looks fine but there
 is something that really bugs me: there are no minor ticks between the
 X-axis and the first major tick.

 Here is the code:


 #lang racket

 (require plot)

 (parameterize ([plot-y-transform log-transform]
[plot-y-ticks (log-ticks #:number 6)])
   (define xs (range 1 11))
   (define ys (map (λ (x) (exp x)) xs))
   (plot (points (map vector xs ys) #:y-min 1)))


 I tried different values for #:number to no avail. Is this the intended
 functionality?

 Best,
 Marduk

 --
 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] Re: Continued Fraction Arithmetic Package

2015-08-26 Thread Benjamin Greenman
Package installed. Thanks!

On Wed, Aug 26, 2015 at 12:58 PM, Deren Dohoda deren.doh...@gmail.com
wrote:

 Thanks Vincent, I have done so.

 On Wed, Aug 26, 2015 at 12:41 PM, Vincent St-Amour 
 stamo...@eecs.northwestern.edu wrote:

 It's easy.

 Just click the login link on the top-right, and create an account.

 Once that's done, you can add your new package to the listing by
 clicking upload. Enter the package meta-information, and have the
 source point to your github repo.

 At that point, anyone will be able to run

 `raco pkg install continued-fractions`

 (assuming you name your package that) and install your library. The
 build status and docs for your package will also be available from
 pkgs.racket-lang.org.

 It's quick, simple and painless, and will make your library easily
 available to anyone.

 Vincent




 On Wed, 26 Aug 2015 10:12:26 -0500,
 Deren Dohoda wrote:
 
  I did not. I wasn't sure what the protocol is there.
 
  Deren
 
  On Aug 26, 2015 11:10 AM, Vincent St-Amour
  stamo...@eecs.northwestern.edu wrote:
 
  Awesome!
 
  Did you add it to pkgs.racket-lang.org? I didn't find it.
 
  Vincent
 
 
 
  On Tue, 25 Aug 2015 21:54:55 -0500,
  Deren Dohoda wrote:
  
   Hello Racketeers,
  
   The continued fractions package has made its first release,
  complete
   with documentation and hopefully enough good examples. You can
  find it
   at
   https://github.com/derend/continued-fractions
  
   Short story:
   (require continued-fractions)
   logs, exponentials, trig, hyperbolic trig, precision guarantees,
   arithmetic (+ - * /)
   (require continued-fractions/bases)
   arbitrary base conversion with user-configurable alphabets
  
   Future plans: add the interface for creating custom continued
  fractions.
   Any user-requested content I am good enough to implement.
  
   Enjoy!
  
   Deren
  
   --
   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.


-- 
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] Impersonating a 0-arity function

2015-08-22 Thread Benjamin Greenman
I'd like to change the result of a 0-arity function, but I need help
crafting the right magic spell. Here's my attempt.


#lang racket/base

(struct wrap (vals)) ;; Wrap a list
(define (create) '())

(define create-wrap
  (impersonate-procedure create
(lambda ()
  ;;(values ;; -- this will run, but it doesn't wrap the result
like I'd like.
  (values (lambda (r) (wrap r))
  (values)

(create-wrap) ;; Error! result arity mismatch: expected 1, got 0.

-- 
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] Impersonating a 0-arity function

2015-08-21 Thread Benjamin Greenman
I'd like to change the result of a 0-arity function, but I need help
crafting the right magic spell. Here's my attempt -- this even possible?


#lang racket/base

(struct wrap (vals)) ;; Wrap a list
(define (create) '())

(define create-wrap
  (impersonate-procedure create
(lambda ()
  ;;(values ;; -- this will run, but it doesn't wrap the result
like I'd like.
  (values (lambda (r) (wrap r))
  (values)

(create-wrap) ;; Error! result arity mismatch: expected 1, got 0.

-- 
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] Impersonating a 0-arity function

2015-08-21 Thread Benjamin Greenman
Thank you!

On Fri, Aug 21, 2015 at 2:38 PM, Matthew Flatt mfl...@cs.utah.edu wrote:

 At Fri, 21 Aug 2015 12:44:08 -0400, Benjamin Greenman wrote:
  I'd like to change the result of a 0-arity function, but I need help
  crafting the right magic spell. Here's my attempt -- this even possible?
 
 
  #lang racket/base
 
  (struct wrap (vals)) ;; Wrap a list
  (define (create) '())
 
  (define create-wrap
(impersonate-procedure create
  (lambda ()
;;(values ;; -- this will run, but it doesn't wrap the result
  like I'd like.
(values (lambda (r) (wrap r))
(values)
 
  (create-wrap) ;; Error! result arity mismatch: expected 1, got 0.

 Just return the result-wrapping function, since that's one result
 (i.e., one more than the zero results for zero arguments):

  #lang racket/base

  (struct wrap (vals)) ;; Wrap a list
  (define (create) '())

  (define create-wrap
(impersonate-procedure create
  (lambda ()
(lambda (r) (wrap r)

  (create-wrap)




 --
 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] Typesetting Racket code

2015-08-12 Thread Benjamin Greenman
I'm not sure about squarer, but using `\boldsymbol` will get you bolder.

\usepackage{amsmath}
 \RktSym{$\boldsymbol\lambda$}

(But I think the right answer is to use a font family with a lambda symbol.
I bet that's what Scribble does.)

On Wed, Aug 12, 2015 at 2:38 PM, Paul van der Walt paul.vanderw...@inria.fr
 wrote:


 On 2015-08-12 at 18:29, quoth Jens Axel Søgaard:
  How does Scribble typeset the lambda?

 I was curious about that too.  As far as i can see, it's something like
 my first option was.

\newcommand{\RktSym}[1]{\inColor{IdentifierColor}{#1}}
...
\RktSym{$\lambda$}

 Unfortunately, that renders the λ in an italicised (sans-serif?) font,
 which looks out of place next to fixed-width (teletype) which is used
 for code snippets.  See the attached image.

 I'm probably obsessing over this a bit too much, but a bolder, squarer
 lambda would be just the ticket for me.  Compare this to how the λ looks
 in, say, DrRacket -- it uses the same font the rest of the code.

 Cheers,
 p.

 --
 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] Wanted: Crazy nested lambda test cases

2015-07-23 Thread Benjamin Greenman
Worked fine on two of my favorite examples.

Example 1, grows exponentially under call-by-name reduction
  H = (\ (f x) (f f (x x))
  W = (\ (x) (x x))
  (H H (W W))

Example 2, variable-arity map adapted from
http://www.brics.dk/RS/01/10/BRICS-RS-01-10.pdf

On Thu, Jul 23, 2015 at 2:09 PM, Emmanuel Schanzer 
schan...@bootstrapworld.org wrote:

 Hi all - I’ve recently pushed a tweak to WeScheme’s compiler, which should
 do a better job matching DrRacket’s behavior when compiling
 lambdas-within-lambdas, and lambdas-that-produce-lambdas.

 I’m looking for sadistic test cases (preferably *not* using local) to
 stress-test. Anybody have any good ones lying around? Feel free to take the
 new compiler for a spin at http://197.wescheme.appspot.com/openEditor,
 but please send me any good tests that you have as well!

 Thanks so much,
 Emmanuel Schanzer
 -
 Bootstrap Program Director
 617-792-2438
 schan...@bootstrapworld.org

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


lam.rkt
Description: Binary data


Re: [racket-users] plot: change pen cap?

2015-07-08 Thread Benjamin Greenman
Yes, I guess it is a clipping issue. Along the same lines, I had wanted to
make a few plots with the same plot area, but these plots had different
width y-axis labels so plot-width and plot-height did not help (neither did
padding the smaller labels with \u00A0).

Can I open some github issues for these? I'd be happy to label myself as
responsible.

On Fri, Jul 3, 2015 at 12:50 PM, Neil Toronto neil.toro...@gmail.com
wrote:

 On 07/02/2015 08:37 PM, Benjamin Greenman wrote:


 On Thu, Jul 2, 2015 at 11:23 AM, Neil Toronto neil.toro...@gmail.com
 mailto:neil.toro...@gmail.com wrote:

 rounded ends are the only kind that compose nicely when drawn that way


 Oooh, that's interesting. After sending the first email I'd actually
 gone ahead and hacked make-pen% to always use the square cap -- which
 looked matplotlib good for my plots -- and was planning to expose that
 parameter in a pull request. But I won't anymore.

 For the record, my actual problem was with 2 specific points:

 1. Plot lines extended slightly past the x/y axes


 Is this actually a clipping issue?

  2. Dashed horizontal rules looked better as square lines


 True. So do extra axes, plot boundaries and tick lines.

 I'd be perfectly happy if all the decorations, and renderers that produce
 decoration-looking things like axis lines and rules, always used square
 caps. Maybe even 2D rectangles and other stuff that always draw just
 horizontal and vertical lines. I wouldn't even want a parameter for
 changing them back, pursuant to Plot's looks great without users having to
 think about making it look great design goal.

 Neil ⊥



-- 
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] plot: change pen cap?

2015-07-02 Thread Benjamin Greenman
On Thu, Jul 2, 2015 at 11:23 AM, Neil Toronto neil.toro...@gmail.com
wrote:

 rounded ends are the only kind that compose nicely when drawn that way


Oooh, that's interesting. After sending the first email I'd actually gone
ahead and hacked make-pen% to always use the square cap -- which looked
matplotlib good for my plots -- and was planning to expose that parameter
in a pull request. But I won't anymore.

For the record, my actual problem was with 2 specific points:

1. Plot lines extended slightly past the x/y axes

2. Dashed horizontal rules looked better as square lines

-- 
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 ‘except-in’ to exclude identifiers for a single phase level

2015-06-28 Thread Benjamin Greenman
Sure, you just need to require and provide b at your favorite phase level
in c. Replacing module c with the following makes the rest compile for me:


(module c racket/base
  ;; Require  provide everything except `some-fun` at phase 0
  (require (except-in (submod .. b) some-fn))
  (provide (all-from-out (submod .. b)))
  ;; Require  provide everything at phase 1
  (require (for-syntax (submod .. b)))
  (provide (for-syntax (all-from-out (submod .. b)

On Sun, Jun 28, 2015 at 3:01 AM, Alexis King lexi.lam...@gmail.com wrote:

 I ran across some behavior that I find a little bit surprising. Consider
 the following module:

   #lang racket/base

   ; the definition of some-fn
   (module a racket/base
 (provide some-fn)
 (define (some-fn) (void)))

   ; provides some-fn in multiple phase levels
   (module b racket/base
 (require (submod .. a)
  (for-syntax (submod .. a)))
 (provide some-fn
  (for-syntax some-fn)))

   ; excludes some-fn in phase 0... and phase 1?!
   (module c racket/base
 (require (except-in (submod .. b) some-fn))
 (provide (all-from-out (submod .. b

   (require 'c)
   (begin-for-syntax
 ; not defined!
 some-fn)

 This demonstrates that except-in appears to remove identifiers from *all*
 phase levels, not just phase 0. Is there any way to restrict except-in to a
 particular phase level, or is there a different way to accomplish that sort
 of behavior?

 For context, I ran into this while seeing what it would be like to create
 an “r5rs+” lang that permits things like ‘syntax-case’, so I effectively
 want to provide all the bindings from ‘r5rs’, but I want to exclude the
 ‘#%top’, ‘#%datum’, and ‘#%app’ bindings that r5rs exports for phase 1,
 which restrict expressions in phase 1 to only use syntax-rules (I’d replace
 these with the normal bindings exported for phase 0).

 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.


-- 
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 ‘except-in’ to exclude identifiers for a single phase level

2015-06-28 Thread Benjamin Greenman
No problem, just change the provides around. Maybe the problem is that
you're missing the (require (for-syntax ...)) ?

(module c racket/base
  ;; Require  provide everything except `some-fun` at phase 1
  (require (for-syntax (except-in (submod .. b) some-fn)))
  (provide (for-syntax (all-from-out (submod .. b
  ;; Require  provide everything at phase 0
  (require (submod .. b))
  (provide (all-from-out (submod .. b

On Sun, Jun 28, 2015 at 1:16 PM, Alexis King lexi.lam...@gmail.com wrote:

 You're right, that works for including some-fn in phase 1 but not phase 0.
 The trouble is that I actually want the inverse of that: some-fn should be
 defined in phase 0 but not phase 1.

   (require 'c)
   some-fn ; defined here
   (begin-for-syntax
 some-fn) ; not defined here

 I haven't figured out exactly how to make that particular configuration
 work.

  On Jun 28, 2015, at 01:21, Benjamin Greenman bl...@cornell.edu wrote:
 
  Sure, you just need to require and provide b at your favorite phase
 level in c. Replacing module c with the following makes the rest compile
 for me:
 
 
  (module c racket/base
;; Require  provide everything except `some-fun` at phase 0
(require (except-in (submod .. b) some-fn))
(provide (all-from-out (submod .. b)))
;; Require  provide everything at phase 1
(require (for-syntax (submod .. b)))
(provide (for-syntax (all-from-out (submod .. b)

 --
 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 ‘except-in’ to exclude identifiers for a single phase level

2015-06-28 Thread Benjamin Greenman
Oops. Then I'd want to change the all-from-outs to something more specific,
or (preferably) change b to only provide some-fn at one level and make the
requiring module be more specific.

On Sun, Jun 28, 2015 at 5:40 PM, Alexis King lexi.lam...@gmail.com wrote:

 Nope, that doesn’t work. If you try it, you’ll see that some-fn is still
 available in phase 1. That’s because the (provide (all-from-out (submod
 .. b))) provides it as well, which is why I’ve been struggling.

  On Jun 28, 2015, at 13:09, Benjamin Greenman bl...@cornell.edu wrote:
 
  No problem, just change the provides around. Maybe the problem is that
 you're missing the (require (for-syntax ...)) ?
 
  (module c racket/base
;; Require  provide everything except `some-fun` at phase 1
(require (for-syntax (except-in (submod .. b) some-fn)))
(provide (for-syntax (all-from-out (submod .. b
;; Require  provide everything at phase 0
(require (submod .. b))
(provide (all-from-out (submod .. b

 --
 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] plot: change pen cap?

2015-06-24 Thread Benjamin Greenman
I'd like to change the pen cap on my racket/plot images from the default
'round to 'butt. What's the easiest way to do this?

-- 
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] Re: [racket] updated trycode.io

2015-05-31 Thread Benjamin Greenman
Just tried teaching a friend Racket with this and noticed that typing an
extra right paren causes the interpreter to hang. We had to refresh the
page.


On Tue, Mar 3, 2015 at 2:48 PM, Floyd Arguello floyd.argue...@gmail.com
wrote:


 Its fixed - nginx cached the racket web server response :P

 Thanks for pointing that out.

 Best,
 Floyd


  On Mar 3, 2015, at 12:17 PM, Stephen Chang stch...@ccs.neu.edu wrote:

 This is really neat!

 I tried the guessing game and it seems to have a bug though?

  (guess)

  50

  (smaller)

  25

  (bigger)

  37

  (bigger)

  37

 On Tue, Mar 3, 2015 at 10:22 AM, Matthias Felleisen
 matth...@ccs.neu.edu wrote:


 Thanks. This is really neat. When (if really) I ever find time, I would
 love to help with putting more of Realm out there like this. -- Matthias



 On Mar 2, 2015, at 10:10 PM, Floyd Arguello floyd.argue...@gmail.com
 wrote:

  trycode.io has been updated with the Guess My Number game from Realm of
 Racket. Please take a look and tell me your thoughts.

 Cheers,
 Floyd

 
 Racket Users list:
 http://lists.racket-lang.org/users



 
 Racket Users list:
 http://lists.racket-lang.org/users


 
   Racket Users list:
   http://lists.racket-lang.org/users



-- 
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] racket-explorer now deals with cyclic/mutable data

2015-05-22 Thread Benjamin Greenman
Awesome!

-- 
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] test submodules vs tests in separate file

2015-05-21 Thread Benjamin Greenman
 Three advantages of `test` submodules interspersed with the implementation
 code:


Here's a fourth: no need for tricks like require/expose to sneak around
interfaces.

-- 
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] Type error using in-list on empty list

2015-05-19 Thread Benjamin Greenman
This program raises a type error about unsafe-car

(for ([x : Void (in-list '())]) x)

So far, I've found ways to remove the error
1. Remove the annotation on x
2. Remove the in-list hint
3. Use a non-empty list

Is this a bug?

-- 
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] type mismatch: given (Listof Error)

2015-05-11 Thread Benjamin Greenman
This program gives a confusing error message. Does anyone know why the xs
in the body doesn't have type (List Foo)?

The error message is much better if the return type is (Listof Integer).
It only complains about Foo being unbound instead of Foo unbound and got
a listof error.

;; ---

#lang typed/racket/base

(: foo (- (Listof Foo) Integer))
(define (foo xs) xs)

 Type Checker: parse error in type;
 type name `Foo' is unbound
 Type Checker: type mismatch
  expected: Integer
  given: (Listof Error)
  in: xs

-- 
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] Typed analog of integer-in contract

2015-04-20 Thread Benjamin Greenman
The contract integer-in lets me guarantee an integer is within a certain
range.

(define/contract (mod3 n)
  (- integer? (integer-in 0 2))
  (modulo n 3))

Is there a similar way to specify a type for an integer range? Or do I need
to use a union type? (I'd really like to specify a range containing over a
million integers.)

-- 
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] DrRacket plugin to remove trailing whitespace on save?

2015-04-13 Thread Benjamin Greenman
On Mon, Apr 13, 2015 at 1:51 PM, 'John Clements' via users-redirect 
us...@plt-scheme.org wrote:


 On Apr 13, 2015, at 10:26 AM, Robby Findler ro...@eecs.northwestern.edu
 wrote:

  You could just make delete-trailing-whitespace a keyboard shortcut
 instead.
 
  Another approach would be to add a mode that colors trailing
  whitespace in that ugly greeny/yellowy color that DrRacket uses for
  the your code is more than 102 columns warning.

 +1 to this. I think I’d definitely like this independent of a mechanism to
 trim on save.


+1


 Robby
 
  On Mon, Apr 13, 2015 at 12:06 PM, 'John Clements' via users-redirect
  us...@plt-scheme.org wrote:
 
  On Apr 13, 2015, at 2:29 AM, Jon Zeppieri zeppi...@gmail.com wrote:
 
  Robby,
 
  This is my first crack at a DrRacket tool (not to mention an uncommon
  foray into Racket's class system), so what I'm doing may not be...
  sane. But if you're willing to take a look:
  [https://github.com/97jaz/drwhitespace]. At any rate, it isn't a lot
  of code. I based the general structure on Asumu Takikawa's
  drracket-vim-tool.
 
  It's supposed to have the same effect as emacs's
 `delete-trailing-whitespace`.
  I still need to add a preference setting to turn it on or off. (Maybe
  that should be based on the editor's mode?)
 
  I’d really like to use this tool.
 
  Here’s one problem that I see: there’s a hidden invariant in DrRacket
 (and all editors) that when a buffer is unchanged, saving it won’t change
 the file on disk. Actually, I think you can state this in a bunch of
 different ways. I forsee hard-to-understand errors arising from a silent
 change-on-save (unless I’m misreading your code?). Personally, I think I’d
 be more likely to use a tool that requests permission to scrub trailing
 whitespace when saving a file.  I also think that this should probably be
 limited to racket and scribble files, and I’m guessing that the easiest way
 to distinguish these would be to use the filename extension.
 
  Please don’t let me stop you from doing this, though, this is something
 I’ve wanted for quite a while!
 
  Many thanks,
 
  John
 
 
  -Jon
 
 
  On Sun, Apr 12, 2015 at 6:14 PM, Robby Findler
  ro...@eecs.northwestern.edu wrote:
  No but Max changed the way return works so there should be less
 whitespace
  added going forward.
 
  Writing a script to trim whitespace from line-endings would work well
 if it
  were to use text% IMO. Use load-file to get a file and then the
 paragraph
  methods to find line endings and then delete stuff and ace the file
 again.
 
  Robby
 
  On Sunday, April 12, 2015, Jon Zeppieri zeppi...@gmail.com wrote:
 
  Does such a think already exist?
 
  -Jon
 
  --
  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.
 
  --
  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.


-- 
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: glob, for Unix-style globbing

2015-03-31 Thread Benjamin Greenman
I've pushed a script for globbing to the package server. It exports two
functions, `glob` and `in-glob`. I hope that some day functions like these
can be in racket/file, but until then, enjoy.

(glob ./files/*.rkt)
Returns a list of all files ending with the .rkt extension in the directory
files

(in-glob ./files/*.rkt)
Same as glob, but returns a generator-backed sequence.


By default, the results don't contain dotfiles. You can override this
behavior by giving #t as a second argument, like in `(glob * #t)`.

The ~ character isn't expanded right now, but otherwise these functions
should do the same thing as your favorite shell. Let me know if you find a
counterexample.
https://github.com/bennn/glob/issues

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