[racket-users] trace facility in Racket?

2020-03-20 Thread dgtlcmo
Does anyone know how to trace functions inside a closure?  I would like to 
trace hanoi-move, however find that with MIT Scheme I need to place (trace) 
within the closure (hanoi n), otherwise the trace will not occur.

Can a trace like this be performed in Racket?

Thanks

 (define (hanoi n)
  (define (pmd from to)
(display "Move ")
(display from)
(display " to ")
(display to)
(newline)
'())
  (define (hanoi-move n from to spare)
(cond ((= n 0) '())
 ((= n 1) (pmd from to))
 (else
  (hanoi-move (- n 1) from spare to)
  (hanoi-move 1 from to spare)
  (hanoi-move (- n 1) spare to from
  (hanoi-move n "A" "B" "C"))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/92efb57d-6f32-47bb-89ec-98d9a4a5aed0%40googlegroups.com.


Re: [racket-users] FYI, build from HEAD fails in realloc()

2020-03-20 Thread 'John Clements' via Racket Users
Bang! I was wrong. Here’s another similar trace:

raco setup: 6 running: 
/pfds/pfds/scribblings/functional-data-structures.scrbl
raco setup: 4 running: /jbc-utils/gradeserver/gradeserver.scrbl
raco setup: 3 running: /htdp-doc/scribblings/htdp-langs/htdp-langs.scrbl
raco setup: 2 running: /images-doc/images/scribblings/images.scrbl
raco setup: 0 running: /macro-debugger/macro-debugger/macro-debugger.scrbl
raco setup: 7 running: /math-doc/math/scribblings/math.scrbl
raco setup: 5 running: /net-doc/net/scribblings/net.scrbl
raco setup: 1 running: /compatibility-doc/mzlib/scribblings/mzlib.scrbl
raco setup: 4 running: /racket-doc/openssl/openssl.scrbl
raco setup: 4 running: 
/optimization-coach/optimization-coach/scribblings/optimization-coach.scrbl
raco setup: 4 running: 
/option-contract-doc/scribblings/option-contract.scrbl
raco setup: 4 running: /net-doc/net/scribblings/osx-ssl.scrbl
raco setup: 5 running: /overeasy/overeasy.scrbl
raco setup: 4 running: /parsack/parsack/parsack.scrbl
raco setup: 1 running: /parser-tools-doc/parser-tools/parser-tools.scrbl
raco setup: 5 running: /pict-doc/pict/scribblings/pict.scrbl
raco setup: 1 running: 
/pict-snip-doc/scribblings/pict-snip/pict-snip.scrbl
raco setup: 4 running: 
/picturing-programs/picturing-programs/picturing-programs.scrbl
raco setup: 1 running: /racket-doc/pkg/scribblings/pkg.scrbl
raco setup: 4 running: /plai-doc/scribblings/plai.scrbl
raco setup: 1 running: /planet-doc/planet/planet.scrbl
raco setup: 4 running: /plot-doc/plot/scribblings/plot.scrbl
racket(54631,0x762f) malloc: *** error for object 0x12f96cdc8: pointer 
being realloc'd was not allocated
racket(54631,0x762f) malloc: *** set a breakpoint in malloc_error_break 
to debug
make[2]: *** [in-place-setup] Abort trap: 6
make[1]: *** [plain-in-place] Error 2
make: *** [in-place] Error 2
make  240.77s user 75.70s system 398% cpu 1:19.32 total


> On Mar 20, 2020, at 3:11 PM, 'John Clements' via Racket Users 
>  wrote:
> 
> Here’s the tail of a build of racket HEAD that just failed during a call to 
> realloc(). I went back far enough to be sure I had a full record of what was 
> running on cores 0-7. 
> 
> I strongly suspect this is not reproducible, and I don’t think there’s any 
> further information that would be useful here, alas.
> 
> John
> 
> raco setup: 1 running: 
> /pfds/pfds/scribblings/functional-data-structures.scrbl
> raco setup: 0 running: 
> /future-visualizer/future-visualizer/scribblings/future-visualizer.scrbl
> raco setup: 4 running: /games/scribblings/games.scrbl
> raco setup: 6 running: 
> /racket-doc/scribblings/getting-started/getting-started.scrbl
> raco setup: 6 running: /games/gl-board-game/gl-board-game.scrbl
> raco setup: 0 running: /GLPK/glpk/glpk.scrbl
> raco setup: 5 running: /jbc-utils/gradeserver/gradeserver.scrbl
> read-compiled-linklet: version mismatch  expected: "7.6.0.17"  found: "7.6"  
> in: 
> /Users/clements/git-clements/pkgs/jbc-utils/gradeserver/compiled/gradeserver_scrbl.zo
>  context...:
>   read-linklet-or-directory
>   read-dispatch
>   read-syntax
>   default-load-handler
>   standard-module-name-resolver
>   module-path-index-resolve
>   module-declared?
>   /Users/clements/racket/pkgs/racket-index/setup/scribble.rkt:1529:27
>   /Users/clements/racket/pkgs/racket-index/setup/scribble.rkt:904:0: 
> load-doc/ensure-prefix
>   /Users/clements/racket/pkgs/racket-index/setup/scribble.rkt:1162:13
>   .../parallel-do.rkt:388:17
>   
> /Users/clements/racket/racket/collects/setup/../racket/private/more-scheme.rkt:261:28
>   /Users/clements/racket/racket/collects/setup/parallel-do.rkt:441:20: loop
> 
>  context...:
>   /Users/clements/racket/racket/collects/setup/parallel-do.rkt:332:4: 
> work-done method in list-queue%
>   /Users/clements/racket/racket/collects/setup/parallel-do.rkt:282:17
>   /Users/clements/racket/racket/collects/setup/parallel-do.rkt:236:4
>   /Users/clements/racket/pkgs/racket-index/setup/scribble.rkt:138:0: 
> setup-scribblings
>   /Users/clements/racket/racket/collects/setup/setup-core.rkt:72:0: setup-core
>   "/Users/clements/racket/racket/collects/setup/main.rkt": [running body]
>   temp35_0
>   for-loop
>   run-module-instance!
>   "/Users/clements/racket/racket/collects/raco/main.rkt": [running body]
>   temp35_0
>   for-loop
>   run-module-instance!
>   perform-require!
> raco setup: 5 running: /graph-doc/graph/scribblings/graph.scrbl
> raco setup: 4 running: /htdp-doc/graphics/scribblings/graphics.scrbl
> raco setup: 6 running: /gregor-doc/gregor/scribblings/gregor.scrbl
> raco setup: 2 running: /gui-doc/scribblings/gui/gui.scrbl
> raco setup: 0 running: 
> /handin/handin-server/scribblings/handin-server.scrbl
> raco setup: 4 running: /racket-doc/help/help.scrbl
> raco setup: 4 running: /htdp-doc/htdp/htdp.scrbl
> raco setup: 0 running: /htdp-doc/scribblings/htdp-langs/htdp-langs.scrbl
> raco setup: 5 running: /htdp-doc/scribblings/htdp-langs/htdp-ptr.scrbl
> raco setup: 5 running: /html-doc/html/html.scrbl

[racket-users] FYI, build from HEAD fails in realloc()

2020-03-20 Thread 'John Clements' via Racket Users
Here’s the tail of a build of racket HEAD that just failed during a call to 
realloc(). I went back far enough to be sure I had a full record of what was 
running on cores 0-7. 

I strongly suspect this is not reproducible, and I don’t think there’s any 
further information that would be useful here, alas.

John

raco setup: 1 running: 
/pfds/pfds/scribblings/functional-data-structures.scrbl
raco setup: 0 running: 
/future-visualizer/future-visualizer/scribblings/future-visualizer.scrbl
raco setup: 4 running: /games/scribblings/games.scrbl
raco setup: 6 running: 
/racket-doc/scribblings/getting-started/getting-started.scrbl
raco setup: 6 running: /games/gl-board-game/gl-board-game.scrbl
raco setup: 0 running: /GLPK/glpk/glpk.scrbl
raco setup: 5 running: /jbc-utils/gradeserver/gradeserver.scrbl
read-compiled-linklet: version mismatch  expected: "7.6.0.17"  found: "7.6"  
in: 
/Users/clements/git-clements/pkgs/jbc-utils/gradeserver/compiled/gradeserver_scrbl.zo
  context...:
   read-linklet-or-directory
   read-dispatch
   read-syntax
   default-load-handler
   standard-module-name-resolver
   module-path-index-resolve
   module-declared?
   /Users/clements/racket/pkgs/racket-index/setup/scribble.rkt:1529:27
   /Users/clements/racket/pkgs/racket-index/setup/scribble.rkt:904:0: 
load-doc/ensure-prefix
   /Users/clements/racket/pkgs/racket-index/setup/scribble.rkt:1162:13
   .../parallel-do.rkt:388:17
   
/Users/clements/racket/racket/collects/setup/../racket/private/more-scheme.rkt:261:28
   /Users/clements/racket/racket/collects/setup/parallel-do.rkt:441:20: loop

  context...:
   /Users/clements/racket/racket/collects/setup/parallel-do.rkt:332:4: 
work-done method in list-queue%
   /Users/clements/racket/racket/collects/setup/parallel-do.rkt:282:17
   /Users/clements/racket/racket/collects/setup/parallel-do.rkt:236:4
   /Users/clements/racket/pkgs/racket-index/setup/scribble.rkt:138:0: 
setup-scribblings
   /Users/clements/racket/racket/collects/setup/setup-core.rkt:72:0: setup-core
   "/Users/clements/racket/racket/collects/setup/main.rkt": [running body]
   temp35_0
   for-loop
   run-module-instance!
   "/Users/clements/racket/racket/collects/raco/main.rkt": [running body]
   temp35_0
   for-loop
   run-module-instance!
   perform-require!
raco setup: 5 running: /graph-doc/graph/scribblings/graph.scrbl
raco setup: 4 running: /htdp-doc/graphics/scribblings/graphics.scrbl
raco setup: 6 running: /gregor-doc/gregor/scribblings/gregor.scrbl
raco setup: 2 running: /gui-doc/scribblings/gui/gui.scrbl
raco setup: 0 running: 
/handin/handin-server/scribblings/handin-server.scrbl
raco setup: 4 running: /racket-doc/help/help.scrbl
raco setup: 4 running: /htdp-doc/htdp/htdp.scrbl
raco setup: 0 running: /htdp-doc/scribblings/htdp-langs/htdp-langs.scrbl
raco setup: 5 running: /htdp-doc/scribblings/htdp-langs/htdp-ptr.scrbl
raco setup: 5 running: /html-doc/html/html.scrbl
raco setup: 4 running: /html-parsing/html-parsing.scrbl
raco setup: 4 running: /http/http/http.scrbl
raco setup: 5 running: /images-doc/images/scribblings/images.scrbl
raco setup: 4 running: /racket-doc/scribblings/inside/inside.scrbl
raco setup: 3 running: /racket-doc/json/json.scrbl
raco setup: 3 running: /latex-pict/latex-pict/scribblings/latex-pict.scrbl
raco setup: 3 running: /lazy/lazy.scrbl
raco setup: 4 running: /levenshtein/levenshtein.scrbl
raco setup: 4 running: /racket-index/scribblings/main/license.scrbl
raco setup: 4 running: 
/racket-index/scribblings/main/user/local-redirect.scrbl
raco setup: 3 running: /macro-debugger/macro-debugger/macro-debugger.scrbl
raco setup: 4 running: /make/make.scrbl
raco setup: 6 running: /markdown/markdown/markdown.scrbl
raco setup: 4 running: /math-doc/math/scribblings/math.scrbl
raco setup: 6 running: /mcfly/mcfly.scrbl
raco setup: 6 running: /memoize/memoize/memoize.scrbl
raco setup: 6 running: /molis-hai/molis-hai/molis-hai.scrbl
raco setup: 7 running: /racket-doc/scribblings/more/more.scrbl
raco setup: 6 running: /gui-doc/mrlib/scribblings/mrlib.scrbl
raco setup: 2 running: /mysterx/scribblings/mysterx.scrbl
raco setup: 2 running: /mzcom/mzcom.scrbl
raco setup: 7 running: /compatibility-doc/mzlib/scribblings/mzlib.scrbl
raco setup: 2 running: /mzscheme-doc/mzscheme/mzscheme.scrbl
raco setup: 2 running: /net-doc/net/scribblings/net.scrbl
raco setup: 6 running: /racket-doc/openssl/openssl.scrbl
racket(52764,0x7ab17000) malloc: *** error for object 0x1735d8dc8: pointer 
being realloc'd was not allocated
racket(52764,0x7ab17000) malloc: *** set a breakpoint in malloc_error_break 
to debug
make[2]: *** [in-place-setup] Abort trap: 6
make[1]: *** [plain-in-place] Error 2
make: *** [in-place] Error 2
make  4947.41s user 1268.91s system 356% cpu 29:03.26 total


raco setup: 2 running: /mysterx/scribblings/mysterx.scrbl
raco setup: 2 running: /mzcom/mzcom.scrbl
raco setup: 7 running: /compatibility-doc/mzlib/scribblings/mzlib.scrbl
raco setup: 2 running: /mzscheme-doc/mzscheme/mzscheme.scrbl
raco setup: 

Re: [racket-users] auto-indentation... off by one^H^H^Hsome?

2020-03-20 Thread 'John Clements' via Racket Users
Made a pull request, many thanks!

John

> On Mar 20, 2020, at 1:36 PM, Robby Findler  wrote:
> 
> Looks right to me!
> 
> On Fri, Mar 20, 2020 at 3:26 PM John Clements  
> wrote:
> Could I add a note like this to the docs for the indentation function?
> 
> “NB: indentation results depend on the graphical context associated with the 
> object; it may be necessary to associate the object with an editor-canvas and 
> frame in order to get the expected results."
> 
> That text might not actually be accurate…
> 
> John
> 
> > On Mar 20, 2020, at 1:16 PM, John Clements  
> > wrote:
> > 
> > Ah! this solves the issue. many thanks.
> > 
> >> On Mar 20, 2020, at 1:03 PM, Robby Findler  
> >> wrote:
> >> 
> >> Looks like you need a display or the text gets confused about how big
> >> (in pixels) characters really are:
> >> 
> >> #lang racket/gui
> >> (require framework)
> >> (define f (new frame% [label ""]))
> >> (define t (new racket:text%))
> >> (define ec (new editor-canvas% [parent f] [editor t]))
> >> (send t insert "(+3\n4)")
> >> (send t freeze-colorer)
> >> (send t tabify-all)
> >> (display (send t get-text))
> >> 
> >> On Fri, Mar 20, 2020 at 2:12 PM John Clements  
> >> wrote:
> >>> 
> >>> That actually solves a bunch of problems for me… but strangely, not the 
> >>> initial one. If, for instance, I tabify
> >>> 
> >>> (+  3
> >>> 4)
> >>> 
> >>> using the tabify-all method, the line with the four gets an indentation 
> >>> of 2, not 8. This is definitely different from DrRacket’s behavior.
> >>> 
> >>> Any idea how to fix this?
> >>> 
> >>> (cc:ing racket-users without permission, hope that’s okay?)
> >>> 
> >>> John
> >>> 
> >>> 
>  On Mar 20, 2020, at 12:05 PM, John Clements  
>  wrote:
>  
>  Ah! That’s probably a better solution, I’ll just do that. I searched for 
>  “indent”, should I try to add that as a search term for the “tabify-all” 
>  method?
>  
>  Many thanks!
>  
>  (Also, sending mail to the list using “us...@racket-lang.org” seems to 
>  be broken right now for me, sigh.)
>  
>  John
>  
> > On Mar 20, 2020, at 12:01 PM, Robby Findler  
> > wrote:
> > 
> > I'm not sure of the details but did you consider just inserting it
> > into a racket:text% and then calling the tabify-all method?
> > 
> > Robby
> > 
> > On Fri, Mar 20, 2020 at 1:26 PM John Clements 
> >  wrote:
> >> 
> >> Hmm… followup problem. If I try to indent the string “#|\nabc\n|#” 
> >> (that is, a block comment), the compute-racket-amount-to-indent method 
> >> returns #f. Is this a bug, or just undocumented behavior?
> >> 
> >> John
> >> 
> >>> On Mar 20, 2020, at 10:41 AM, John Clements 
> >>>  wrote:
> >>> 
> >>> I’m writing code to help me grade exams, and one of the issues I’ve 
> >>> run into is that the code coming out of the LMS is all totally 
> >>> unindented. So, for instance, a student’s response might read:
> >>> 
> >>> ;Closures help a function value remember what substitutions have 
> >>> already been applied to it.
> >>> '{vars {{x {lam {x} {+ 1 x}}}
> >>> {y {lam {y} {+ 3 y
> >>> {+ {x 2} {y 4}}}
> >>> 
> >>> Obviously, it would be a lot easier to grade that if it was indented.
> >>> 
> >>> Excellent! A chance to whip up a quick-and-dirty auto-indenter, using 
> >>> DrRacket’s indentation framework. Specifically, the 
> >>> `compute-racket-amount-to-indent` method of racket:text<%>.
> >>> 
> >>> I’m pleased to report almost total success, aside from one strange 
> >>> off-by-one error that I’m looking for help with.  To see it, here’s 
> >>> the result of my auto-indenter on the prior block:
> >>> 
> >>> '{vars {{x {lam {x} {+ 1 x}}}
> >>>{y {lam {y} {+ 3 y
> >>>  {+ {x 2} {y 4}}}
> >>> 
> >>> (if you’re viewing this in a proportional-width font, that’s going to 
> >>> look terrible, sorry.)
> >>> 
> >>> The issue is that the final plus line isn’t lined up with the 
> >>> curly-brace that’s two chars after the end of `vars`… instead, it’s 
> >>> one character to the left.
> >>> 
> >>> A much simpler test case is simply running on “(+ 3\n4)”. Rather than 
> >>> getting the 4 lined up with the 3, I get it one character to the left.
> >>> 
> >>> And… uh oh. A more illuminating test case occurs when I run my code 
> >>> on “(+  3\n4)”. That is, I put a bunch more spaces before the 3. 
> >>> After indentation, the 4 is still only indented by two characters. So 
> >>> it looks like the `compute-racket-amount-to-indent` method is not 
> >>> looking for the token following the first one following the paren in 
> >>> the prior line (which would account for all the spaces), but just 
> >>> adding one to the last position of the first token following the 
> >>> paren. This makes me wonder 

Re: [racket-users] auto-indentation... off by one^H^H^Hsome?

2020-03-20 Thread Robby Findler
Looks right to me!

On Fri, Mar 20, 2020 at 3:26 PM John Clements 
wrote:

> Could I add a note like this to the docs for the indentation function?
>
> “NB: indentation results depend on the graphical context associated with
> the object; it may be necessary to associate the object with an
> editor-canvas and frame in order to get the expected results."
>
> That text might not actually be accurate…
>
> John
>
> > On Mar 20, 2020, at 1:16 PM, John Clements 
> wrote:
> >
> > Ah! this solves the issue. many thanks.
> >
> >> On Mar 20, 2020, at 1:03 PM, Robby Findler 
> wrote:
> >>
> >> Looks like you need a display or the text gets confused about how big
> >> (in pixels) characters really are:
> >>
> >> #lang racket/gui
> >> (require framework)
> >> (define f (new frame% [label ""]))
> >> (define t (new racket:text%))
> >> (define ec (new editor-canvas% [parent f] [editor t]))
> >> (send t insert "(+3\n4)")
> >> (send t freeze-colorer)
> >> (send t tabify-all)
> >> (display (send t get-text))
> >>
> >> On Fri, Mar 20, 2020 at 2:12 PM John Clements <
> cleme...@brinckerhoff.org> wrote:
> >>>
> >>> That actually solves a bunch of problems for me… but strangely, not
> the initial one. If, for instance, I tabify
> >>>
> >>> (+  3
> >>> 4)
> >>>
> >>> using the tabify-all method, the line with the four gets an
> indentation of 2, not 8. This is definitely different from DrRacket’s
> behavior.
> >>>
> >>> Any idea how to fix this?
> >>>
> >>> (cc:ing racket-users without permission, hope that’s okay?)
> >>>
> >>> John
> >>>
> >>>
>  On Mar 20, 2020, at 12:05 PM, John Clements <
> cleme...@brinckerhoff.org> wrote:
> 
>  Ah! That’s probably a better solution, I’ll just do that. I searched
> for “indent”, should I try to add that as a search term for the
> “tabify-all” method?
> 
>  Many thanks!
> 
>  (Also, sending mail to the list using “us...@racket-lang.org” seems
> to be broken right now for me, sigh.)
> 
>  John
> 
> > On Mar 20, 2020, at 12:01 PM, Robby Findler <
> ro...@cs.northwestern.edu> wrote:
> >
> > I'm not sure of the details but did you consider just inserting it
> > into a racket:text% and then calling the tabify-all method?
> >
> > Robby
> >
> > On Fri, Mar 20, 2020 at 1:26 PM John Clements <
> cleme...@brinckerhoff.org> wrote:
> >>
> >> Hmm… followup problem. If I try to indent the string “#|\nabc\n|#”
> (that is, a block comment), the compute-racket-amount-to-indent method
> returns #f. Is this a bug, or just undocumented behavior?
> >>
> >> John
> >>
> >>> On Mar 20, 2020, at 10:41 AM, John Clements <
> cleme...@brinckerhoff.org> wrote:
> >>>
> >>> I’m writing code to help me grade exams, and one of the issues
> I’ve run into is that the code coming out of the LMS is all totally
> unindented. So, for instance, a student’s response might read:
> >>>
> >>> ;Closures help a function value remember what substitutions have
> already been applied to it.
> >>> '{vars {{x {lam {x} {+ 1 x}}}
> >>> {y {lam {y} {+ 3 y
> >>> {+ {x 2} {y 4}}}
> >>>
> >>> Obviously, it would be a lot easier to grade that if it was
> indented.
> >>>
> >>> Excellent! A chance to whip up a quick-and-dirty auto-indenter,
> using DrRacket’s indentation framework. Specifically, the
> `compute-racket-amount-to-indent` method of racket:text<%>.
> >>>
> >>> I’m pleased to report almost total success, aside from one strange
> off-by-one error that I’m looking for help with.  To see it, here’s the
> result of my auto-indenter on the prior block:
> >>>
> >>> '{vars {{x {lam {x} {+ 1 x}}}
> >>>{y {lam {y} {+ 3 y
> >>>  {+ {x 2} {y 4}}}
> >>>
> >>> (if you’re viewing this in a proportional-width font, that’s going
> to look terrible, sorry.)
> >>>
> >>> The issue is that the final plus line isn’t lined up with the
> curly-brace that’s two chars after the end of `vars`… instead, it’s one
> character to the left.
> >>>
> >>> A much simpler test case is simply running on “(+ 3\n4)”. Rather
> than getting the 4 lined up with the 3, I get it one character to the left.
> >>>
> >>> And… uh oh. A more illuminating test case occurs when I run my
> code on “(+  3\n4)”. That is, I put a bunch more spaces before the 3.
> After indentation, the 4 is still only indented by two characters. So it
> looks like the `compute-racket-amount-to-indent` method is not looking for
> the token following the first one following the paren in the prior line
> (which would account for all the spaces), but just adding one to the last
> position of the first token following the paren. This makes me wonder
> whether DrRacket actually uses this method to indent.
> >>>
> >>> Hmm.
> >>>
> >>> Well, here’s the code to reproduce this. Note that there’s an
> obvious bug/assumption in that my code doesn’t account for any existing
> leading 

Re: [racket-users] auto-indentation... off by one^H^H^Hsome?

2020-03-20 Thread 'John Clements' via Racket Users
Could I add a note like this to the docs for the indentation function?

“NB: indentation results depend on the graphical context associated with the 
object; it may be necessary to associate the object with an editor-canvas and 
frame in order to get the expected results."

That text might not actually be accurate…

John

> On Mar 20, 2020, at 1:16 PM, John Clements  wrote:
> 
> Ah! this solves the issue. many thanks.
> 
>> On Mar 20, 2020, at 1:03 PM, Robby Findler  wrote:
>> 
>> Looks like you need a display or the text gets confused about how big
>> (in pixels) characters really are:
>> 
>> #lang racket/gui
>> (require framework)
>> (define f (new frame% [label ""]))
>> (define t (new racket:text%))
>> (define ec (new editor-canvas% [parent f] [editor t]))
>> (send t insert "(+3\n4)")
>> (send t freeze-colorer)
>> (send t tabify-all)
>> (display (send t get-text))
>> 
>> On Fri, Mar 20, 2020 at 2:12 PM John Clements  
>> wrote:
>>> 
>>> That actually solves a bunch of problems for me… but strangely, not the 
>>> initial one. If, for instance, I tabify
>>> 
>>> (+  3
>>> 4)
>>> 
>>> using the tabify-all method, the line with the four gets an indentation of 
>>> 2, not 8. This is definitely different from DrRacket’s behavior.
>>> 
>>> Any idea how to fix this?
>>> 
>>> (cc:ing racket-users without permission, hope that’s okay?)
>>> 
>>> John
>>> 
>>> 
 On Mar 20, 2020, at 12:05 PM, John Clements  
 wrote:
 
 Ah! That’s probably a better solution, I’ll just do that. I searched for 
 “indent”, should I try to add that as a search term for the “tabify-all” 
 method?
 
 Many thanks!
 
 (Also, sending mail to the list using “us...@racket-lang.org” seems to be 
 broken right now for me, sigh.)
 
 John
 
> On Mar 20, 2020, at 12:01 PM, Robby Findler  
> wrote:
> 
> I'm not sure of the details but did you consider just inserting it
> into a racket:text% and then calling the tabify-all method?
> 
> Robby
> 
> On Fri, Mar 20, 2020 at 1:26 PM John Clements  
> wrote:
>> 
>> Hmm… followup problem. If I try to indent the string “#|\nabc\n|#” (that 
>> is, a block comment), the compute-racket-amount-to-indent method returns 
>> #f. Is this a bug, or just undocumented behavior?
>> 
>> John
>> 
>>> On Mar 20, 2020, at 10:41 AM, John Clements  
>>> wrote:
>>> 
>>> I’m writing code to help me grade exams, and one of the issues I’ve run 
>>> into is that the code coming out of the LMS is all totally unindented. 
>>> So, for instance, a student’s response might read:
>>> 
>>> ;Closures help a function value remember what substitutions have 
>>> already been applied to it.
>>> '{vars {{x {lam {x} {+ 1 x}}}
>>> {y {lam {y} {+ 3 y
>>> {+ {x 2} {y 4}}}
>>> 
>>> Obviously, it would be a lot easier to grade that if it was indented.
>>> 
>>> Excellent! A chance to whip up a quick-and-dirty auto-indenter, using 
>>> DrRacket’s indentation framework. Specifically, the 
>>> `compute-racket-amount-to-indent` method of racket:text<%>.
>>> 
>>> I’m pleased to report almost total success, aside from one strange 
>>> off-by-one error that I’m looking for help with.  To see it, here’s the 
>>> result of my auto-indenter on the prior block:
>>> 
>>> '{vars {{x {lam {x} {+ 1 x}}}
>>>{y {lam {y} {+ 3 y
>>>  {+ {x 2} {y 4}}}
>>> 
>>> (if you’re viewing this in a proportional-width font, that’s going to 
>>> look terrible, sorry.)
>>> 
>>> The issue is that the final plus line isn’t lined up with the 
>>> curly-brace that’s two chars after the end of `vars`… instead, it’s one 
>>> character to the left.
>>> 
>>> A much simpler test case is simply running on “(+ 3\n4)”. Rather than 
>>> getting the 4 lined up with the 3, I get it one character to the left.
>>> 
>>> And… uh oh. A more illuminating test case occurs when I run my code on 
>>> “(+  3\n4)”. That is, I put a bunch more spaces before the 3. After 
>>> indentation, the 4 is still only indented by two characters. So it 
>>> looks like the `compute-racket-amount-to-indent` method is not looking 
>>> for the token following the first one following the paren in the prior 
>>> line (which would account for all the spaces), but just adding one to 
>>> the last position of the first token following the paren. This makes me 
>>> wonder whether DrRacket actually uses this method to indent.
>>> 
>>> Hmm.
>>> 
>>> Well, here’s the code to reproduce this. Note that there’s an obvious 
>>> bug/assumption in that my code doesn’t account for any existing leading 
>>> spaces on a line, but none of my examples have leading spaces following 
>>> newlines.
>>> 
>>> Advice appreciated!
>>> 
>>> John
>>> 
>>> 
>>> 
>>> 

Re: [racket-users] auto-indentation... off by one^H^H^Hsome?

2020-03-20 Thread 'John Clements' via Racket Users
Unimportant thing one: this code had the same issue as mine, but as Robby 
points out, the issue is the way the text% is constructed; I was just creating 
a racket:text% directly, which (IIUC) doesn’t have a graphics context, so the 
auto-indenter can’t figure out how wide characters are.

Less unimportant thing: It seems like a whole bunch of people are writing 
racket linting/style-checking code right now, which seems like an unfortunate 
duplication of resources. I’ve got one that I’m about to deploy to my students 
that uses a combination of raw-text and read-but-not-expanded syntax, and right 
now it’s looking for simple things like functions without purpose statements, 
lines with only trailing parens, and uses of ‘cast’ that aren’t in fairly 
specific places (to wit, the bodies of functions named “parse”, a kind of 
ridiculous hack).

If you released your code, then we could all use it, and shower you day and 
night with bug reports and irritating feature requests!

John

> On Mar 20, 2020, at 12:21 PM, Benjamin Lerner  wrote:
> 
> In my auto-indenter and style checker (not yet a package that’s widely 
> available): evidently, there are some preferences that control which 
> constructs get tabified differently than expected. So I tweak those 
> preferences before invoking tabify-all. (In my case, I’m trying to support 
> two plausible indentation styles, depending on whether students have 
> different defaults set, so I compute the indentation twice.)
> 
> #lang racket
> 
> ;; Read in a source file and tabify it according to the following three 
> tabbing styles:
> ;;
> ;; 1. Untabbed (as writen directly in the file)
> ;; 2. Standard DrRacket tabbing excluding the big-bang default.
> ;;big-bang indents as:
> ;;  (big-bang a
> ;;b)
> ;; 3. Standard DrRacket tabbing including the big-bang default.
> ;;big-bang indents as:
> ;;  (big-bang a
> ;;b)
> ;;
> ;; (-> racket:text%? (values string? string? string?))
> ;;
> ;; WARNING!!! This function likely has effects based on the framework 
> library. It should NOT touch
> ;; your filesystem. However, this module should not be instantiated alongside
> ;; other DrRacket preferences.
> ;;
> (provide tabify-text)
> 
> (require framework/preferences)
> 
> (define (tabify-text t)
>   (parameterize* ([preferences:low-level-put-preferences
>(λ _ (void))]
>   [preferences:low-level-get-preference
>(λ _ #f)])
> (define untabbed (send t get-text))
> (define tabbed
>   (let ()
> (match-define (list table rx1 rx2 rx3 rx4)
>   (preferences:get 'framework:tabify))
> (hash-remove! table 'big-bang)
> (preferences:set 'framework:tabify
>  (list table rx1 rx2 rx3 rx4))
> (send t tabify-all)
> (send t get-text)))
> (define lambda-tabbed
>   (let ()
> (match-define (list table rx1 rx2 rx3 rx4)
>   (preferences:get 'framework:tabify))
> (hash-set! table 'big-bang 'lambda)
> (preferences:set 'framework:tabify
>  (list table rx1 rx2 rx3 rx4))
> (send t tabify-all)
> (send t get-text)))
> (values untabbed tabbed lambda-tabbed)))
> 
> On 3/20/20 3:12 PM, ‘John Clements’ via Racket Users wrote:
> 
> 
> 
>> That actually solves a bunch of problems for me… but strangely, not the 
>> initial one. If, for instance, I tabify
>> 
>> (+  3
>>   4)
>> 
>> using the tabify-all method, the line with the four gets an indentation of 
>> 2, not 8. This is definitely different from DrRacket’s behavior.
>> 
>> Any idea how to fix this?
>> 
>> (cc:ing racket-users without permission, hope that’s okay?)
>> 
>> John
>> 
>> 
>> 
>>> On Mar 20, 2020, at 12:05 PM, John Clements 
>>>  wrote:
>>> 
>>> Ah! That’s probably a better solution, I’ll just do that. I searched for 
>>> “indent”, should I try to add that as a search term for the “tabify-all” 
>>> method?
>>> 
>>> Many thanks!
>>> 
>>> (Also, sending mail to the list using “
>>> us...@racket-lang.org
>>> ” seems to be broken right now for me, sigh.)
>>> 
>>> John
>>> 
>>> 
 On Mar 20, 2020, at 12:01 PM, Robby Findler 
  wrote:
 
 I'm not sure of the details but did you consider just inserting it
 into a racket:text% and then calling the tabify-all method?
 
 Robby
 
 On Fri, Mar 20, 2020 at 1:26 PM John Clements 
 
  wrote:
 
> Hmm… followup problem. If I try to indent the string “#|\nabc\n|#” (that 
> is, a block comment), the compute-racket-amount-to-indent method returns 
> #f. Is this a bug, or just undocumented behavior?
> 
> John
> 
> 
>> On Mar 20, 2020, at 10:41 AM, John Clements 
>>  wrote:
>> 
>> I’m writing code to help me grade exams, and one of the issues I’ve run 
>> into is that the code coming out of the LMS is all totally unindented. 
>> So, for instance, a student’s 

Re: [racket-users] auto-indentation... off by one^H^H^Hsome?

2020-03-20 Thread 'John Clements' via Racket Users
Ah! this solves the issue. many thanks.

> On Mar 20, 2020, at 1:03 PM, Robby Findler  wrote:
> 
> Looks like you need a display or the text gets confused about how big
> (in pixels) characters really are:
> 
> #lang racket/gui
> (require framework)
> (define f (new frame% [label ""]))
> (define t (new racket:text%))
> (define ec (new editor-canvas% [parent f] [editor t]))
> (send t insert "(+3\n4)")
> (send t freeze-colorer)
> (send t tabify-all)
> (display (send t get-text))
> 
> On Fri, Mar 20, 2020 at 2:12 PM John Clements  
> wrote:
>> 
>> That actually solves a bunch of problems for me… but strangely, not the 
>> initial one. If, for instance, I tabify
>> 
>> (+  3
>>  4)
>> 
>> using the tabify-all method, the line with the four gets an indentation of 
>> 2, not 8. This is definitely different from DrRacket’s behavior.
>> 
>> Any idea how to fix this?
>> 
>> (cc:ing racket-users without permission, hope that’s okay?)
>> 
>> John
>> 
>> 
>>> On Mar 20, 2020, at 12:05 PM, John Clements  
>>> wrote:
>>> 
>>> Ah! That’s probably a better solution, I’ll just do that. I searched for 
>>> “indent”, should I try to add that as a search term for the “tabify-all” 
>>> method?
>>> 
>>> Many thanks!
>>> 
>>> (Also, sending mail to the list using “us...@racket-lang.org” seems to be 
>>> broken right now for me, sigh.)
>>> 
>>> John
>>> 
 On Mar 20, 2020, at 12:01 PM, Robby Findler  
 wrote:
 
 I'm not sure of the details but did you consider just inserting it
 into a racket:text% and then calling the tabify-all method?
 
 Robby
 
 On Fri, Mar 20, 2020 at 1:26 PM John Clements  
 wrote:
> 
> Hmm… followup problem. If I try to indent the string “#|\nabc\n|#” (that 
> is, a block comment), the compute-racket-amount-to-indent method returns 
> #f. Is this a bug, or just undocumented behavior?
> 
> John
> 
>> On Mar 20, 2020, at 10:41 AM, John Clements  
>> wrote:
>> 
>> I’m writing code to help me grade exams, and one of the issues I’ve run 
>> into is that the code coming out of the LMS is all totally unindented. 
>> So, for instance, a student’s response might read:
>> 
>> ;Closures help a function value remember what substitutions have already 
>> been applied to it.
>> '{vars {{x {lam {x} {+ 1 x}}}
>> {y {lam {y} {+ 3 y
>> {+ {x 2} {y 4}}}
>> 
>> Obviously, it would be a lot easier to grade that if it was indented.
>> 
>> Excellent! A chance to whip up a quick-and-dirty auto-indenter, using 
>> DrRacket’s indentation framework. Specifically, the 
>> `compute-racket-amount-to-indent` method of racket:text<%>.
>> 
>> I’m pleased to report almost total success, aside from one strange 
>> off-by-one error that I’m looking for help with.  To see it, here’s the 
>> result of my auto-indenter on the prior block:
>> 
>> '{vars {{x {lam {x} {+ 1 x}}}
>> {y {lam {y} {+ 3 y
>>   {+ {x 2} {y 4}}}
>> 
>> (if you’re viewing this in a proportional-width font, that’s going to 
>> look terrible, sorry.)
>> 
>> The issue is that the final plus line isn’t lined up with the 
>> curly-brace that’s two chars after the end of `vars`… instead, it’s one 
>> character to the left.
>> 
>> A much simpler test case is simply running on “(+ 3\n4)”. Rather than 
>> getting the 4 lined up with the 3, I get it one character to the left.
>> 
>> And… uh oh. A more illuminating test case occurs when I run my code on 
>> “(+  3\n4)”. That is, I put a bunch more spaces before the 3. After 
>> indentation, the 4 is still only indented by two characters. So it looks 
>> like the `compute-racket-amount-to-indent` method is not looking for the 
>> token following the first one following the paren in the prior line 
>> (which would account for all the spaces), but just adding one to the 
>> last position of the first token following the paren. This makes me 
>> wonder whether DrRacket actually uses this method to indent.
>> 
>> Hmm.
>> 
>> Well, here’s the code to reproduce this. Note that there’s an obvious 
>> bug/assumption in that my code doesn’t account for any existing leading 
>> spaces on a line, but none of my examples have leading spaces following 
>> newlines.
>> 
>> Advice appreciated!
>> 
>> John
>> 
>> 
>> 
>> 
>> #lang racket
>> 
>> (require framework)
>> 
>> ;; given a string of racket text, return the corresponding indented 
>> string
>> ;; NB: CURRENTLY ASSUMES ALL LINES START WITH ZERO SPACES.
>> (define (string-indent text-to-indent)
>> (define t (new racket:text%))
>> (send t erase)
>> (send t insert text-to-indent 0)
>> (define num-paragraphs (add1 (send t last-paragraph)))
>> (define indents
>> (for/list ([n (in-range num-paragraphs)])
>>   

[racket-users] Re: auto-indentation... off by one^H^H^Hsome?

2020-03-20 Thread Robby Findler
Looks like you need a display or the text gets confused about how big
(in pixels) characters really are:

#lang racket/gui
(require framework)
(define f (new frame% [label ""]))
(define t (new racket:text%))
(define ec (new editor-canvas% [parent f] [editor t]))
(send t insert "(+3\n4)")
(send t freeze-colorer)
(send t tabify-all)
(display (send t get-text))

On Fri, Mar 20, 2020 at 2:12 PM John Clements  wrote:
>
> That actually solves a bunch of problems for me… but strangely, not the 
> initial one. If, for instance, I tabify
>
> (+  3
>   4)
>
> using the tabify-all method, the line with the four gets an indentation of 2, 
> not 8. This is definitely different from DrRacket’s behavior.
>
> Any idea how to fix this?
>
> (cc:ing racket-users without permission, hope that’s okay?)
>
> John
>
>
> > On Mar 20, 2020, at 12:05 PM, John Clements  
> > wrote:
> >
> > Ah! That’s probably a better solution, I’ll just do that. I searched for 
> > “indent”, should I try to add that as a search term for the “tabify-all” 
> > method?
> >
> > Many thanks!
> >
> > (Also, sending mail to the list using “us...@racket-lang.org” seems to be 
> > broken right now for me, sigh.)
> >
> > John
> >
> >> On Mar 20, 2020, at 12:01 PM, Robby Findler  
> >> wrote:
> >>
> >> I'm not sure of the details but did you consider just inserting it
> >> into a racket:text% and then calling the tabify-all method?
> >>
> >> Robby
> >>
> >> On Fri, Mar 20, 2020 at 1:26 PM John Clements  
> >> wrote:
> >>>
> >>> Hmm… followup problem. If I try to indent the string “#|\nabc\n|#” (that 
> >>> is, a block comment), the compute-racket-amount-to-indent method returns 
> >>> #f. Is this a bug, or just undocumented behavior?
> >>>
> >>> John
> >>>
>  On Mar 20, 2020, at 10:41 AM, John Clements  
>  wrote:
> 
>  I’m writing code to help me grade exams, and one of the issues I’ve run 
>  into is that the code coming out of the LMS is all totally unindented. 
>  So, for instance, a student’s response might read:
> 
>  ;Closures help a function value remember what substitutions have already 
>  been applied to it.
>  '{vars {{x {lam {x} {+ 1 x}}}
>  {y {lam {y} {+ 3 y
>  {+ {x 2} {y 4}}}
> 
>  Obviously, it would be a lot easier to grade that if it was indented.
> 
>  Excellent! A chance to whip up a quick-and-dirty auto-indenter, using 
>  DrRacket’s indentation framework. Specifically, the 
>  `compute-racket-amount-to-indent` method of racket:text<%>.
> 
>  I’m pleased to report almost total success, aside from one strange 
>  off-by-one error that I’m looking for help with.  To see it, here’s the 
>  result of my auto-indenter on the prior block:
> 
>  '{vars {{x {lam {x} {+ 1 x}}}
>   {y {lam {y} {+ 3 y
> {+ {x 2} {y 4}}}
> 
>  (if you’re viewing this in a proportional-width font, that’s going to 
>  look terrible, sorry.)
> 
>  The issue is that the final plus line isn’t lined up with the 
>  curly-brace that’s two chars after the end of `vars`… instead, it’s one 
>  character to the left.
> 
>  A much simpler test case is simply running on “(+ 3\n4)”. Rather than 
>  getting the 4 lined up with the 3, I get it one character to the left.
> 
>  And… uh oh. A more illuminating test case occurs when I run my code on 
>  “(+  3\n4)”. That is, I put a bunch more spaces before the 3. After 
>  indentation, the 4 is still only indented by two characters. So it looks 
>  like the `compute-racket-amount-to-indent` method is not looking for the 
>  token following the first one following the paren in the prior line 
>  (which would account for all the spaces), but just adding one to the 
>  last position of the first token following the paren. This makes me 
>  wonder whether DrRacket actually uses this method to indent.
> 
>  Hmm.
> 
>  Well, here’s the code to reproduce this. Note that there’s an obvious 
>  bug/assumption in that my code doesn’t account for any existing leading 
>  spaces on a line, but none of my examples have leading spaces following 
>  newlines.
> 
>  Advice appreciated!
> 
>  John
> 
> 
> 
> 
>  #lang racket
> 
>  (require framework)
> 
>  ;; given a string of racket text, return the corresponding indented 
>  string
>  ;; NB: CURRENTLY ASSUMES ALL LINES START WITH ZERO SPACES.
>  (define (string-indent text-to-indent)
>  (define t (new racket:text%))
>  (send t erase)
>  (send t insert text-to-indent 0)
>  (define num-paragraphs (add1 (send t last-paragraph)))
>  (define indents
>   (for/list ([n (in-range num-paragraphs)])
> (define par-start (send t paragraph-start-position n))
> (list par-start
>   (send t compute-racket-amount-to-indent
> par-start
>   

Re: [racket-users] Re: auto-indentation... off by one^H^H^Hsome?

2020-03-20 Thread Benjamin Lerner
In my auto-indenter and style checker (not yet a package that’s widely 
available): evidently, there are some preferences that control which 
constructs get tabified differently than expected. So I tweak those 
preferences before invoking |tabify-all|. (In my case, I’m trying to 
support two plausible indentation styles, depending on whether students 
have different defaults set, so I compute the indentation twice.)


|#lang racket ;; Read in a source file and tabify it according to the 
following three tabbing styles: ;; ;; 1. Untabbed (as writen directly in 
the file) ;; 2. Standard DrRacket tabbing excluding the big-bang 
default. ;; big-bang indents as: ;; (big-bang a ;; b) ;; 3. Standard 
DrRacket tabbing including the big-bang default. ;; big-bang indents as: 
;; (big-bang a ;; b) ;; ;; (-> racket:text%? (values string? string? 
string?)) ;; ;; WARNING!!! This function likely has effects based on the 
framework library. It should NOT touch ;; your filesystem. However, this 
module should not be instantiated alongside ;; other DrRacket 
preferences. ;; (provide tabify-text) (require framework/preferences) 
(define (tabify-text t) (parameterize* 
([preferences:low-level-put-preferences (λ _ (void))] 
[preferences:low-level-get-preference (λ _ #f)]) (define untabbed (send 
t get-text)) (define tabbed (let () (match-define (list table rx1 rx2 
rx3 rx4) (preferences:get 'framework:tabify)) (hash-remove! table 
'big-bang) (preferences:set 'framework:tabify (list table rx1 rx2 rx3 
rx4)) (send t tabify-all) (send t get-text))) (define lambda-tabbed (let 
() (match-define (list table rx1 rx2 rx3 rx4) (preferences:get 
'framework:tabify)) (hash-set! table 'big-bang 'lambda) (preferences:set 
'framework:tabify (list table rx1 rx2 rx3 rx4)) (send t tabify-all) 
(send t get-text))) (values untabbed tabbed lambda-tabbed))) |


On 3/20/20 3:12 PM, ‘John Clements’ via Racket Users wrote:


That actually solves a bunch of problems for me… but strangely, not the initial 
one. If, for instance, I tabify

(+  3
   4)

using the tabify-all method, the line with the four gets an indentation of 2, 
not 8. This is definitely different from DrRacket’s behavior.

Any idea how to fix this?

(cc:ing racket-users without permission, hope that’s okay?)

John



On Mar 20, 2020, at 12:05 PM, John Clements  wrote:

Ah! That’s probably a better solution, I’ll just do that. I searched for 
“indent”, should I try to add that as a search term for the “tabify-all” method?

Many thanks!

(Also, sending mail to the list using “us...@racket-lang.org” seems to be 
broken right now for me, sigh.)

John


On Mar 20, 2020, at 12:01 PM, Robby Findler  wrote:

I'm not sure of the details but did you consider just inserting it
into a racket:text% and then calling the tabify-all method?

Robby

On Fri, Mar 20, 2020 at 1:26 PM John Clements  wrote:

Hmm… followup problem. If I try to indent the string “#|\nabc\n|#” (that is, a 
block comment), the compute-racket-amount-to-indent method returns #f. Is this 
a bug, or just undocumented behavior?

John


On Mar 20, 2020, at 10:41 AM, John Clements  wrote:

I’m writing code to help me grade exams, and one of the issues I’ve run into is 
that the code coming out of the LMS is all totally unindented. So, for 
instance, a student’s response might read:

;Closures help a function value remember what substitutions have already been 
applied to it.
'{vars {{x {lam {x} {+ 1 x}}}
{y {lam {y} {+ 3 y
{+ {x 2} {y 4}}}

Obviously, it would be a lot easier to grade that if it was indented.

Excellent! A chance to whip up a quick-and-dirty auto-indenter, using DrRacket’s 
indentation framework. Specifically, the `compute-racket-amount-to-indent` method of 
racket:text<%>.

I’m pleased to report almost total success, aside from one strange off-by-one 
error that I’m looking for help with.  To see it, here’s the result of my 
auto-indenter on the prior block:

'{vars {{x {lam {x} {+ 1 x}}}
  {y {lam {y} {+ 3 y
{+ {x 2} {y 4}}}

(if you’re viewing this in a proportional-width font, that’s going to look 
terrible, sorry.)

The issue is that the final plus line isn’t lined up with the curly-brace 
that’s two chars after the end of `vars`… instead, it’s one character to the 
left.

A much simpler test case is simply running on “(+ 3\n4)”. Rather than getting 
the 4 lined up with the 3, I get it one character to the left.

And… uh oh. A more illuminating test case occurs when I run my code on “(+  
3\n4)”. That is, I put a bunch more spaces before the 3. After indentation, the 
4 is still only indented by two characters. So it looks like the 
`compute-racket-amount-to-indent` method is not looking for the token following 
the first one following the paren in the prior line (which would account for 
all the spaces), but just adding one to the last position of the first token 
following the paren. This makes me wonder whether DrRacket actually uses this 
method to indent.

Hmm.

Well, here’s the 

[racket-users] Re: auto-indentation... off by one^H^H^Hsome?

2020-03-20 Thread 'John Clements' via Racket Users
That actually solves a bunch of problems for me… but strangely, not the initial 
one. If, for instance, I tabify

(+  3
  4)

using the tabify-all method, the line with the four gets an indentation of 2, 
not 8. This is definitely different from DrRacket’s behavior.

Any idea how to fix this?

(cc:ing racket-users without permission, hope that’s okay?)

John


> On Mar 20, 2020, at 12:05 PM, John Clements  wrote:
> 
> Ah! That’s probably a better solution, I’ll just do that. I searched for 
> “indent”, should I try to add that as a search term for the “tabify-all” 
> method?
> 
> Many thanks!
> 
> (Also, sending mail to the list using “us...@racket-lang.org” seems to be 
> broken right now for me, sigh.)
> 
> John
> 
>> On Mar 20, 2020, at 12:01 PM, Robby Findler  
>> wrote:
>> 
>> I'm not sure of the details but did you consider just inserting it
>> into a racket:text% and then calling the tabify-all method?
>> 
>> Robby
>> 
>> On Fri, Mar 20, 2020 at 1:26 PM John Clements  
>> wrote:
>>> 
>>> Hmm… followup problem. If I try to indent the string “#|\nabc\n|#” (that 
>>> is, a block comment), the compute-racket-amount-to-indent method returns 
>>> #f. Is this a bug, or just undocumented behavior?
>>> 
>>> John
>>> 
 On Mar 20, 2020, at 10:41 AM, John Clements  
 wrote:
 
 I’m writing code to help me grade exams, and one of the issues I’ve run 
 into is that the code coming out of the LMS is all totally unindented. So, 
 for instance, a student’s response might read:
 
 ;Closures help a function value remember what substitutions have already 
 been applied to it.
 '{vars {{x {lam {x} {+ 1 x}}}
 {y {lam {y} {+ 3 y
 {+ {x 2} {y 4}}}
 
 Obviously, it would be a lot easier to grade that if it was indented.
 
 Excellent! A chance to whip up a quick-and-dirty auto-indenter, using 
 DrRacket’s indentation framework. Specifically, the 
 `compute-racket-amount-to-indent` method of racket:text<%>.
 
 I’m pleased to report almost total success, aside from one strange 
 off-by-one error that I’m looking for help with.  To see it, here’s the 
 result of my auto-indenter on the prior block:
 
 '{vars {{x {lam {x} {+ 1 x}}}
  {y {lam {y} {+ 3 y
{+ {x 2} {y 4}}}
 
 (if you’re viewing this in a proportional-width font, that’s going to look 
 terrible, sorry.)
 
 The issue is that the final plus line isn’t lined up with the curly-brace 
 that’s two chars after the end of `vars`… instead, it’s one character to 
 the left.
 
 A much simpler test case is simply running on “(+ 3\n4)”. Rather than 
 getting the 4 lined up with the 3, I get it one character to the left.
 
 And… uh oh. A more illuminating test case occurs when I run my code on “(+ 
  3\n4)”. That is, I put a bunch more spaces before the 3. After 
 indentation, the 4 is still only indented by two characters. So it looks 
 like the `compute-racket-amount-to-indent` method is not looking for the 
 token following the first one following the paren in the prior line (which 
 would account for all the spaces), but just adding one to the last 
 position of the first token following the paren. This makes me wonder 
 whether DrRacket actually uses this method to indent.
 
 Hmm.
 
 Well, here’s the code to reproduce this. Note that there’s an obvious 
 bug/assumption in that my code doesn’t account for any existing leading 
 spaces on a line, but none of my examples have leading spaces following 
 newlines.
 
 Advice appreciated!
 
 John
 
 
 
 
 #lang racket
 
 (require framework)
 
 ;; given a string of racket text, return the corresponding indented string
 ;; NB: CURRENTLY ASSUMES ALL LINES START WITH ZERO SPACES.
 (define (string-indent text-to-indent)
 (define t (new racket:text%))
 (send t erase)
 (send t insert text-to-indent 0)
 (define num-paragraphs (add1 (send t last-paragraph)))
 (define indents
  (for/list ([n (in-range num-paragraphs)])
(define par-start (send t paragraph-start-position n))
(list par-start
  (send t compute-racket-amount-to-indent
par-start
head-sexp-type
 ;; NB: OBVIOUSLY WRONG, assumes all lines start with zero leading spaces:
 ;; act in reverse order, to avoid messing up the meaning of char posns:
 (for ([indent (in-list (reverse indents))])
  (send t set-position (first indent))
  (define space-string
(list->string (for/list ([i (in-range (second indent))]) #\space)))
  (send t insert space-string))
 (send t get-text))
 
 ;; for now, always return 'other
 (define (head-sexp-type str)
 'other)
 
 
 (define text-to-indent
 #<<|
 ;Closures help a function value remember what substitutions 

[racket-users] Test message sent to racket-users@googlegroups.com

2020-03-20 Thread 'John Clements' via Racket Users
Please ignore, thanks.



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/5ebd201a-8811-482a-b1a1-45a6c6b0d276%40mtasv.net.


[racket-users] Updating openGL bindings

2020-03-20 Thread Hendrik Boom
I have started updating the opengl bindings for Racket.  The version in the 
package library is for OpenGL 4.2; whereas the current version is 4.6.

Since the current version is automatically generated from files
provided by Khronos, and Khronos has changed the format of these
files, it amounts to a complete rewrite.

Those interested can track progress at https://github.com/hendrikboom3/RacketGL

Don't waste your time trying it out.  It won't work at all now.
If it seems to work, it'll be because you're accidentally using the old version.

Advice and comments are welcome.

-- hendrik

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200320164000.mxruq2zfw47fv5ps%40topoi.pooq.com.


Re: [racket-users] Load and execute files

2020-03-20 Thread Ben Greenman
On 3/20/20, Alexandre Rademaker  wrote:
>
> It works! Thank you. The B.rkt (or check.rkt in my last message) can’t have
> the `#lang racket` line. I am still confused about the implications of the
> `#lang racket` line in the file and the module system of Racket.

Great!

In this case, adding #lang puts the body of B.rkt inside a new module,
which would need a require to get the definitions from the toplevel.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R72vD0bk4PZXQyGJAC6tkZs7vVJiWj29mMM4AX6t8GTYA%40mail.gmail.com.


Re: [racket-users] Load and execute files

2020-03-20 Thread Alexandre Rademaker


It works! Thank you. The B.rkt (or check.rkt in my last message) can’t have the 
`#lang racket` line. I am still confused about the implications of the `#lang 
racket` line in the file and the module system of Racket.


> On 20 Mar 2020, at 11:08, Ben Greenman  wrote:
> 
> Does check.rkt start with a #lang line?
> 
> My B.rkt from the last message didn't have a #lang
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/16A9D698-E539-4C63-8A7D-ACCC7D4B2E24%40gmail.com.


Re: [racket-users] Re: HTDP2e part 4: 20.3 Refining Functions dir.rkt

2020-03-20 Thread Ben Greenman
On 3/20/20, Aron Zvi  wrote:
> Thanks for your reply Ben.
>
> I understand that I am supposed to be getting a Dir instance.
> My confusion is indeed regarding the value of the name field of Dir for
> which I get a (full) path symbol of the directory and not just the folder
> name as I would expect.
>
> When I run (create-dir "test") and the test folder is in the same folder as
>
> my racket racket file (using just the folder name as you suggested), I get
> the following Dir instance for which the symbol is still the path to the
> folder from the given root
>
> (make-dir
>  'test
>  (list
>   (make-dir
>*'test/a*
>(list (make-dir *'test/a/docs* '() '()))
>(list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "")
> (make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""
>  (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))
>
> *I am expecting to get this *
>
> (make-dir
>  'test
>  (list
>   (make-dir
>*'a*
>(list (make-dir *'docs* '() '()))
>(list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "")
> (make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""
>  (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))

Ok, I see how that makes Exercise 339 more difficult. Thanks for
pointing this out.

In Racket, I would use `symbol->string` and `file-name-from-path` to
get the name.

In ISL, I'd use `symbol->string` and `string->list` to get started,
then design a function that takes takes all the characters after the
last #\/ character in a list (or all characters if there is no #\/)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R72khWOazwqVnmR2354%3DcbGxRkyn0u-xPTpemYpy1ES7Q%40mail.gmail.com.


Re: [racket-users] Load and execute files

2020-03-20 Thread Ben Greenman
Does check.rkt start with a #lang line?

My B.rkt from the last message didn't have a #lang

On 3/19/20, Alexandre Rademaker  wrote:
>
> Not yet. To be more concrete:
>
> % racket --lib racket -t ex-1.2-3.rkt -t ex-1.7.rkt -t ex-1.8.rkt -r
> check.rkt
> check.rkt:31:7: sum-of-squares-max3: unbound identifier
>   in: sum-of-squares-max3
>   location...:
>check.rkt:31:7
>   context...:
>do-raise-syntax-error
>for-loop
>[repeats 1 more time]
>finish-bodys
>lambda-clause-expander
>for-loop
>loop
>[repeats 6 more times]
>module-begin-k
>expand-module16
>expand-capturing-lifts
>temp118_0
>temp91_0
>compile15
>temp85_0
>loop
>
> The ex* files are the answers of one particular student. The check.rkt
> contains the tests. I am still trying to avoid the necessity of adding the
> (require …) commands in the check.rkt so I can select the student files to
> test in the command line. The -r or -f option cause the same error. The
> (provide …) forms are presented in the ex* files.
>
> Best,
> Alexandre
>
>
>> On 19 Mar 2020, at 20:26, Ben Greenman 
>> wrote:
>>
>>> But I was really expecting that the option -t in the racket command
>>> should
>>> replace the explicit (require…) in B.rkt. Something like
>>>
 racket -t A.rkt -f B.rkt
>>> default-load-handler: expected a `module' declaration, but found
>>> something
>>> else
>>
>> Yes that almost works, but A.rkt needs to provide things for the
>> require to get them.
>>
>> Also, I guess we need --lib racket (maybe my -I racket was a mistake):
>>
>> racket --lib racket -t A.rkt -f B.rkt
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R7ajThHa0W5qHCH42KuGfMowX%2BnZ2K-V6EbUTdFC2zYHQ%40mail.gmail.com.


[racket-users] Re: HTDP2e part 4: 20.3 Refining Functions dir.rkt

2020-03-20 Thread Aron Zvi
Thanks for your reply Ben.

I understand that I am supposed to be getting a Dir instance.
My confusion is indeed regarding the value of the name field of Dir for 
which I get a (full) path symbol of the directory and not just the folder 
name as I would expect.

When I run (create-dir "test") and the test folder is in the same folder as 
my racket racket file (using just the folder name as you suggested), I get 
the following Dir instance for which the symbol is still the path to the 
folder from the given root

(make-dir
 'test
 (list
  (make-dir
   *'test/a*
   (list (make-dir *'test/a/docs* '() '()))
   (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "") 
(make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""
 (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))

*I am expecting to get this *

(make-dir
 'test
 (list
  (make-dir
   *'a*
   (list (make-dir *'docs* '() '()))
   (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 33) "") 
(make-file "me.txt" 0 (make-date 2020 3 20 13 1 42) ""
 (list (make-file ".DS_Store" 6148 (make-date 2020 3 20 13 7 28) "")))



On Thursday, 19 March 2020 17:01:59 UTC+7, Aron Zvi wrote:
>
> Hey guys,
>
> In part 4 section 20.3 Refining Functions I am using (require htdp/dir) 
> and (create-dir DIR-PATH). I get back a Dir instance with name value being 
> a full path symbol of the folder. ie. (make-dir 
> '/Users/SSS/Documents/xyz empty empty). 
> This does not seem to be in line with the exercises in the section where 
> it seems that I should be getting back just the folder name.
> I am missing something? 
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/2ba65d76-e548-4fa0-831e-bfce2f9daca7%40googlegroups.com.