Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-17 Thread Philip McGrath
The error is `set!` reporting that `doc` is undefined, because the `doc`
identifier from `md-module-begin` is introduced hygienically. Also, I
believe your pattern for `md-module-begin` has an extra set of parentheses.
Here is a working version:

#lang racket/base

#lang racket/base

(module lang racket/base
  (require syntax/wrap-modbeg
   (for-syntax racket/base
   syntax/parse))
  (provide (except-out (all-from-out racket/base)
   #%module-begin)
   (rename-out [md-module-begin #%module-begin]))
  (define-syntax handle
(syntax-parser
  [(_ b:expr)
   #:with doc (syntax-local-introduce (datum->syntax #f 'doc))
   #`(set! doc (string-append doc b))]))
  (define-syntax wrapping-modbeg
(make-wrapping-module-begin #'handle))
  (define-syntax md-module-begin
(syntax-parser
  [(_ expr1 ...)
   #:with doc (syntax-local-introduce (datum->syntax #f 'doc))
   #'(wrapping-modbeg (define doc "")
  expr1 ...)])))

(module example (submod ".." lang)
  (provide doc)
  "Example")

(require (submod "." example))

doc



-Philip

On Sat, Aug 18, 2018 at 3:36 AM, Vityou  wrote:

> Stupid question, but how would I saving them in a global variable?  So far
> I have this:
>
> (define-syntax handle
>   (syntax-parser
> [(_ b:expr) #`(set! #,(syntax-local-introduce (datum->syntax #f 'doc))
> (string-append #,(syntax-local-introduce (datum->syntax #f 'doc)) b))]))
>
> (define-syntax wrapping-modbeg
>   (make-wrapping-module-begin #'handle))
>
> (define-syntax md-module-begin
>   (syntax-parser
> [(_ (expr1 ...)) #'(wrapping-modbeg (define doc "")
> expr1 ...)]))
>
> However, it complains that `set!` isn't defined.  I thought it would be
> defined since my module provides `racket/base`.
>
> --
> 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] How to handle define forms in a scribble-like language

2018-08-17 Thread Vityou
Stupid question, but how would I saving them in a global variable?  So far 
I have this:

(define-syntax handle
  (syntax-parser
[(_ b:expr) #`(set! #,(syntax-local-introduce (datum->syntax #f 'doc)) 
(string-append #,(syntax-local-introduce (datum->syntax #f 'doc)) b))]))

(define-syntax wrapping-modbeg
  (make-wrapping-module-begin #'handle))
  
(define-syntax md-module-begin
  (syntax-parser
[(_ (expr1 ...)) #'(wrapping-modbeg (define doc "")
expr1 ...)]))

However, it complains that `set!` isn't defined.  I thought it would be 
defined since my module provides `racket/base`.

-- 
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] Converting bulleted list to s-expression?

2018-08-17 Thread Andrew J
Hi. In a little side project, I'm looking for an simple Racket-y way to 
transform a bulleted list into a tree structure, maybe like sxml.

As an example, this...

- a
  - b c
  - d e f
- g h

would get transformed into something like this...

'(a (b c) (d e f (g h)))

I can see a few ways to do this, from recursively counting indents, right 
through to making a mini DSL (à la *Beautiful Racket*), but I'm wondering 
what a minimal idiomatic solution might look like?


A.

-- 
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] Is there a way to attach struct properties after struct definition?

2018-08-17 Thread Christopher Lemmer Webber
David Storrs writes:

> I've been going through the docs on struct properties, both the Guide and
> the Reference.  I can't see any way to add new properties to a struct at
> runtime (i.e., after the type is defined); is there a way?

Not generally afaik.  This is fairly intentional in Racket's design.

Though I wonder what your use cases are?  Here are some routes you might
explore, depending on what it is:
 - Use a "tagged hashmap" as a kind of cheap object structure
 - Use Racket's classes system, which *does* support runtime composition
   composition of classes (but not of extending an object already
   instantiated with a class)


-- 
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 handle define forms in a scribble-like language

2018-08-17 Thread Shu-Hung You
I would try make-wrapping-module-begin too. Basically, it wraps all
module-level forms that "calculates something" with the syntax object
you gave it. For example, the following program

;; some-language.rkt
#lang racket

(provide (except-out (all-from-out racket)
 #%module-begin)
 (rename-out
  [mb-module-begin #%module-begin]))

(require "some-module-that-provides-add-content.rkt"
 syntax/wrap-modbeg
 (for-syntax syntax/parse))

(define-syntax acc-module-begin
  (make-wrapping-module-begin #'add-content!))

(define-syntax mb-module-begin
  (syntax-parser
[(_ module-level-expr:expr ...)
 #'(acc-module-begin
module-level-expr ...)]))

will be able to transform the code

#lang s-exp "some-language.rkt"
"abcdefg\n"
(define y 5)
"hijk\n"
y

into something like:

#lang s-exp "some-language.rkt"
(add-content! "abcdefg\n")
(define y 5)
(add-content! "hijk\n")
(add-content! y)

If add-content! saves all values in a global variable, the whole
content can be extracted later (after module-level-expr ...).

On Fri, Aug 17, 2018 at 2:23 PM, Vityou  wrote:
> Thanks for the example.  I'm still somewhat new to racket, so I may have to 
> study the example for a while before I understand it.  The 
> `make-wrapping-module-begin` that Alexis mentioned seems to do something 
> similar, so I may end up using that due to it's simplicity.
>
> --
> 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] How to handle define forms in a scribble-like language

2018-08-17 Thread Vityou
Thanks for the example.  I'm still somewhat new to racket, so I may have to 
study the example for a while before I understand it.  The 
`make-wrapping-module-begin` that Alexis mentioned seems to do something 
similar, so I may end up using that due to it's simplicity.

-- 
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] Confused by the behavior of hash->list

2018-08-17 Thread Jussi Salmela
Cool, thanks!

On Fri, Aug 17, 2018 at 7:26 PM Paulo Matos  wrote:

>
>
> On 17/08/18 18:18, Jussi Salmela wrote:
> > Hi all!
> >
> > (I'm on 7.0)
> > Just to jump right to the point here are the hash example lines from the
> User Guide and a few added lines with comments that should make it clear
> what I am confused about:
> >
> > (define ht (make-hash))
> > (hash-set! ht "apple" '(red round))
> > (hash-set! ht "banana" '(yellow long))
> > (writeln ht)
> > (writeln (list? (hash-ref ht "apple")))
> > ;; This is how I assumed hash->list to behave:
> > (writeln (for/list ([key (hash-keys ht)])
> >(list key (hash-ref ht key
> > ;; This is how it behaves:
> > (writeln (hash->list ht))
> >
> >
> > This is the output I get:
> >
> > #hash(("banana" . (yellow long)) ("apple" . (red round)))
> > #t
> > (("apple" (red round)) ("banana" (yellow long)))
> > (("banana" yellow long) ("apple" red round))
> >
> > So I'm confused why the list is "flattened" by hash->list. I can manage
> the situation using for/list, I'm just wondering.
> >
>
> Hi,
>
> The list is not flattened, it's just not showing as much detail as you
> would probably like.
>
> From the docs of hash->list the result type is (listof (cons/c any/c
> any/c))
>
> This is an association list, so the result is:
> (("banana" . (yellow long)) ("apple" . (red round)))
>
> except that racket shows them as lists, and it looks like:
> (("banana" yellow long) ("apple" red round))
>
> This is the counterpart of hash constructors which get an assoc list as
> argument.
>
> > Thanks,
> > Jussi
> >
>
> Kind regards,
>
> --
> Paulo Matos
>

-- 
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] Confused by the behavior of hash->list

2018-08-17 Thread 'Paulo Matos' via Racket Users



On 17/08/18 18:18, Jussi Salmela wrote:
> Hi all!
> 
> (I'm on 7.0)
> Just to jump right to the point here are the hash example lines from the User 
> Guide and a few added lines with comments that should make it clear what I am 
> confused about:
> 
> (define ht (make-hash))
> (hash-set! ht "apple" '(red round))
> (hash-set! ht "banana" '(yellow long))
> (writeln ht)
> (writeln (list? (hash-ref ht "apple")))
> ;; This is how I assumed hash->list to behave:
> (writeln (for/list ([key (hash-keys ht)])
>(list key (hash-ref ht key
> ;; This is how it behaves:
> (writeln (hash->list ht))
> 
> 
> This is the output I get:
> 
> #hash(("banana" . (yellow long)) ("apple" . (red round)))
> #t
> (("apple" (red round)) ("banana" (yellow long)))
> (("banana" yellow long) ("apple" red round))
> 
> So I'm confused why the list is "flattened" by hash->list. I can manage the 
> situation using for/list, I'm just wondering.
> 

Hi,

The list is not flattened, it's just not showing as much detail as you
would probably like.

>From the docs of hash->list the result type is (listof (cons/c any/c any/c))

This is an association list, so the result is:
(("banana" . (yellow long)) ("apple" . (red round)))

except that racket shows them as lists, and it looks like:
(("banana" yellow long) ("apple" red round))

This is the counterpart of hash constructors which get an assoc list as
argument.

> Thanks,
> Jussi
> 

Kind regards,

-- 
Paulo Matos

-- 
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] Is there a way to attach struct properties after struct definition?

2018-08-17 Thread David Storrs
I've been going through the docs on struct properties, both the Guide and
the Reference.  I can't see any way to add new properties to a struct at
runtime (i.e., after the type is defined); is there a 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] What are disappeared-uses?

2018-08-17 Thread David Storrs
On Thu, Aug 16, 2018 at 5:28 PM, Alexis King  wrote:

> > On Aug 16, 2018, at 15:25, David Storrs 
> > wrote:
> >
> > I see 'record-disappeared-uses' and 'with-disappeared-uses' in the
> > docs, but there's nothing that makes clear what you would use them
> > for.  Some digging around on the mailing list suggests that they allow
> > Dr Racket to draw an arrow to a relevant source location.  Do they
> > have any use outside of Dr Racket?
>
>
> They’re also utilized by racket-mode (since racket-mode uses the same
> Check Syntax implementation that DrRacket does), as well as a couple
> other tools that statically analyze Racket programs (such as Ryan’s
> check-requires tool). They are only used by tooling, and they do not
> otherwise affect the behavior of Racket programs, but they should be
> used by “well-behaved” macros so that various tools can understand
> things lost in the process of macroexpansion.
> [...]
>

 Thanks, that all makes sense.  I'll make sure to use it in future.

One more question:  Short of actually doing the full expansion and manually
inspecting the results, how do I know what's going to disappear?

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

2018-08-17 Thread Hendrik Boom
On Thu, Aug 16, 2018 at 07:25:42PM -0400, Deren Dohoda wrote:
> >
> > Thanks for the up-vote but let me explain the “local” rationale here and
> > vote for the ‘inner define’ variant.
> > [snip]...
> >
> >
> > In Racket programs for the world, possibly real, you want to avoid
> > rightward drift. Indenting deeper and deeper makes code appear ‘ugly’ to
> > many eyes, especially those used to other languages. But I will say this is
> > also the one point about ‘ugly’-syntax languages that I have learned to
> > appreciate (plus some concision in names).
> >
> > Internal defines are thus much more preferable than local, let, letrec,
> > and similar constructs. See the Style Guide, where I spelled this out in a
> > bit more detail.
> >
> 
> In general cases I agree with this and view heavy indenting as at a minimum
> code smell but 'let' is so conceptually simple to work with syntactically.

In a Lisp-like language I once introduced a syntactic extension:
  ( a b c / d e f / g h i)
would always be equivalent to
  (a b c ( d e f ( g h i)))

In cases where I would normally tail-nest, this reduced everything to
syntactically non-nested parentheses.  / worked a lot like a semicolon
in conventional languages, but I tended to place it near the beginning of the 
line:
  ( a b c
  / d e f
  / g h i
  )

This was very readable, and did a lot to make Lisp pleasant.

Unfortuntely, there aren't many leftover special characters in Scheme
that can be used for this.  I had not defined / to mean division.

> If I want to extend/alter/make an analogous construction of 'let' it's
> three to twenty lines depending on what I'm doing. I have no clue how to
> start messing with internal definitions in a similar way.

My 'let' construction was simple a three-argument
  ( let a b c)
Iterated for a nonrecursive sequence of lets
  ( let a b
  / let c d
  / if c foo
  / if d bar whateverelse
  )

And this fit nicely with an if-then-else chain as well

-- hendrik

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