Re: [racket-users] Rosetta Code: Level 1st (that's FIRST) with TCL
2015-04-29 14:07 GMT+02:00 Tim Brown tim.br...@cityc.co.uk: On 29/04/15 11:44, Stephen De Gabrielle wrote: Are there any tasks suitable for Rosetta Code that are difficult or impossible in other languages like Python or TCL? (or Lisp, JavaScript, Self/Smalltalk, Forth ...) Something specifically tuned to macros? Actually, (on a cursory search) there are no Anaphoric tasks; and Lisp is always so full of itself with aif et al. I think, though that this goes against the spirit of Rosetta Code's mission: From the very top of http://rosettacode.org/wiki/Rosetta_Code: ... The idea is to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one approach to a problem in learning another. Well, they include gems like: http://rosettacode.org/wiki/Break_OO_privacy Quoting: Show how to access private or protected members of a class in an object-oriented language from outside an instance of the class, without calling non-private or non-protected members of the class as a proxy. The intent is to show how a debugger, serializer, or other meta-programming tool might access information that is barred by normal access methods to the object but can nevertheless be accessed from within the language by some provided escape hatch or reflection mechanism. The intent is specifically not to demonstrate heroic measures such as peeking and poking raw memory. Note that cheating on your type system is almost universally regarded as unidiomatic at best, and poor programming practice at worst. Nonetheless, if your language intentionally maintains a double-standard for OO privacy, here's where you can show it off. -- 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] Another typed/racket puzzle: module+ and scope
Greetings. I have come across another occasion where TR appears to behave in an unexpected way. Consider: % cat add1.rkt #lang typed/racket/base (provide add1) (: add1 (- Integer Integer)) (define (add1 x) (+ x 1)) % cat call-add1.rkt #lang typed/racket/base (require add1.rkt) (module+ main ;(require add1.rkt) (printf 2 + 1 = ~a~% (add1 2))) % racket call-add1.rkt add1.rkt:3:9: Type Checker: missing type for identifier; consider using `require/typed' to import it identifier: add1 from module: add1.rkt in: add1 context...: /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:275:0: type-check /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:411:0: tc-module /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:40:0: tc-setup /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:25:4 standard-module-name-resolver % racket --version Welcome to Racket v6.1.1. % It appears that the add1 is visible within the main module, but its type isn't. Adding the (require) inside the module produces the same error. Adding the (require) inside the module and removing it from the enclosing module does work in this example, but obviously makes add1 invisible in that enclosing module. The TR documentation for #%module-begin http://docs.racket-lang.org/ts-reference/special-forms.html?q=module-begin#%28form._%28%28lib._typed-racket%2Ftyped-racket..rkt%29._~23~25module-begin%29%29 says Otherwise, the #%module-begin form of typed/racket behaves like #%module-begin from racket. I take that to suggest that there should be no surprises here. Looking through the TR reference, the only other mention I can see of modules is in Sect. 5.1 on 'Untyped Utilities'. I can't see any notes on this in the TR Guide Sect. 8, 'Caveats and Limitations'. As an additional remark (and this is a little weird), if I give in, and try to use require/typed, then I get a rather perplexing error: % cat call-add1.rkt #lang typed/racket/base (require add1.rkt) (module+ main (require/typed add1.rkt [add1 (- Integer Integer)]) (printf 5 + 1 = ~a~% (add1 5))) % racket call-add1.rkt add12: unbound identifier; also, no #%top syntax transformer is bound in: add12 context...: /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/utils/require-contract.rkt:13:0 /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:40:0: tc-setup /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:25:4 standard-module-name-resolver % Best wishes, Norman -- Norman Gray : http://nxg.me.uk SUPA School of Physics and Astronomy, University of Glasgow, UK -- 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] Another typed/racket puzzle: module+ and scope
Yes, it’s a known bug that submodules are broken within Typed Racket. I’m not entirely clear on the details, but I believe it is suspected that the reason is actually due to a bug in the macro expander, which should be fixed with Matthew Flatt’s new scope-sets model. Otherwise, I don’t think there’s a particularly good workaround for this issue, so you’ll probably just have to avoid submodules in TR for the time being. On May 4, 2015, at 03:33, Norman Gray nor...@astro.gla.ac.uk wrote: Greetings. I have come across another occasion where TR appears to behave in an unexpected way. Consider: % cat add1.rkt #lang typed/racket/base (provide add1) (: add1 (- Integer Integer)) (define (add1 x) (+ x 1)) % cat call-add1.rkt #lang typed/racket/base (require add1.rkt) (module+ main ;(require add1.rkt) (printf 2 + 1 = ~a~% (add1 2))) % racket call-add1.rkt add1.rkt:3:9: Type Checker: missing type for identifier; consider using `require/typed' to import it identifier: add1 from module: add1.rkt in: add1 context...: /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:275:0: type-check /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:411:0: tc-module /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:40:0: tc-setup /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:25:4 standard-module-name-resolver % racket --version Welcome to Racket v6.1.1. % It appears that the add1 is visible within the main module, but its type isn't. Adding the (require) inside the module produces the same error. Adding the (require) inside the module and removing it from the enclosing module does work in this example, but obviously makes add1 invisible in that enclosing module. The TR documentation for #%module-begin http://docs.racket-lang.org/ts-reference/special-forms.html?q=module-begin#%28form._%28%28lib._typed-racket%2Ftyped-racket..rkt%29._~23~25module-begin%29%29 says Otherwise, the #%module-begin form of typed/racket behaves like #%module-begin from racket. I take that to suggest that there should be no surprises here. Looking through the TR reference, the only other mention I can see of modules is in Sect. 5.1 on 'Untyped Utilities'. I can't see any notes on this in the TR Guide Sect. 8, 'Caveats and Limitations'. As an additional remark (and this is a little weird), if I give in, and try to use require/typed, then I get a rather perplexing error: % cat call-add1.rkt #lang typed/racket/base (require add1.rkt) (module+ main (require/typed add1.rkt [add1 (- Integer Integer)]) (printf 5 + 1 = ~a~% (add1 5))) % racket call-add1.rkt add12: unbound identifier; also, no #%top syntax transformer is bound in: add12 context...: /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/utils/require-contract.rkt:13:0 /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:40:0: tc-setup /Data/LocalApplications/Racket/6.1.1/share/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:25:4 standard-module-name-resolver % Best wishes, Norman -- Norman Gray : http://nxg.me.uk SUPA School of Physics and Astronomy, University of Glasgow, UK -- 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] Fully-expanding a define form in its definition context
Hi, I'm trying to write a macro that fully-expands define forms with the goal of doing some static checking (and thus want the code in racket core so that I know what I'm looking at). Ideally, this macro would work in any context where a define form works. Unfortunately, I'm having a great deal of difficulty using local-expand to get what I want. I've tried a few approaches---the code and simple examples are below. Local expanding as a 'top-level' definition was closest to working because it both fully-expands the definition and inserts binding into the enclosing definition context. Unfortunately, it seems to fail to bind the identifier correctly in the body of its own define. I tried expanding in the 'syntax-local-context', but this causes define-values to complain that it isn't in a definition context (even though syntax-local-context is a module context, which I thought was a definition context). Creating a new definition context makes the expansion work, but the binding goes into the newly created context, which isn't what I want. It also doesn't fully expand the definition. (If I remove define-values from the stop list, it tries to fully-expand but dies complaining that define-values is not in a definition context). I think I'm probably misreading the documentation. Can anyone suggest a correct solution? Thanks, Scott #lang racket (require (for-syntax syntax/parse syntax/parse/lib/function-header)) (define-for-syntax (definition-local-context-expand stx) (local-expand stx (syntax-local-context) '())) (define-syntax (define-expand-top-level stx) (syntax-parse stx #:literals (define-expand-top-level) [(define-expand-top-level header:function-header body ...+) (local-expand #'(define header body ...) 'top-level '())])) (define-syntax (define-expand-local-context stx) (syntax-parse stx #:literals (define-expand-local-context) [(define-expand-local-context header:function-header body ...+) (local-expand #'(define header body ...) (syntax-local-context) '())])) (define-syntax (define-expand-new-context stx) (syntax-parse stx #:literals (define-expand-new-context) [(define-expand-new-context header:function-header body ...+) (let* ([def-ctx (syntax-local-make-definition-context)] [ctx (if (list? (syntax-local-context)) (cons (gensym) (syntax-local-context)) (list (gensym)))] [expd (local-expand #'(define header body ...) ctx (list #'define-values) def-ctx)]) (define ids (syntax-parse expd [(def (id) _) (list #'id)])) (syntax-local-bind-syntaxes ids #f def-ctx) (internal-definition-context-seal def-ctx) expd)])) ; Works as expected (define-expand-top-level (foo n) (+ n 1)) (foo 5) ; Fails to bind fib in the body of the define #;(define-expand-top-level (fib n) (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2) ; fib: unbound identifier in module in: fib ; Attempt to use the local-context (which should be a definition context?) #;(define-expand-local-context (fib n) (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2) ; define-values: not in a definition context in: ; (define-values (fib) (lambda (n) (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2)) ; Creating new definition context makes the expand work but doesn't expose ; the identifiers to the definition context I really want (define-expand-new-context (fib n) (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2) #;(fib 3) ; fib: unbound identifier in module in: fib -- 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] Another typed/racket puzzle: module+ and scope
Alexis, hello. On 2015 May 4, at 16:37, Alexis King lexi.lam...@gmail.com wrote: Yes, it’s a known bug that submodules are broken within Typed Racket. I’m not entirely clear on the details, but I believe it is suspected that the reason is actually due to a bug in the macro expander, which should be fixed with Matthew Flatt’s new scope-sets model. Ah, that's a pity. Otherwise, I don’t think there’s a particularly good workaround for this issue, so you’ll probably just have to avoid submodules in TR for the time being. What I've done is simply to move most of the content of the main submodule into a top-level function, and call that with (current-command-line-arguments). Not as pretty, but it typechecks. Thanks for your help. All the best, Norman -- Norman Gray : http://nxg.me.uk SUPA School of Physics and Astronomy, University of Glasgow, UK -- 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] Rosetta Code: Level 1st (that's FIRST) with TCL
Too early. Tcl is (apparently) first again :( (I'm not sure how is the correct method to count them.) http://timb.net/popular-languages.html # Count Name 1 855 Tcl 2 852 Racket 3 842 Python 4 776 J In the Rosetta webpage # Count Name 1 851 Tcl 2 850 Racket 3 826 Python (???) 4 773 J Gustavo On Wed, Apr 29, 2015 at 3:57 AM, Jens Axel Søgaard jensa...@soegaard.net wrote: Great news! Worth a blog post to follow up on: http://blog.racket-lang.org/2013/03/200_25.html http://blog.racket-lang.org/2014/11/800.html /Jens Axel 2015-04-29 1:38 GMT+02:00 Tim Brown t...@cityc.co.uk: Folks, I've just done a quick burst of cherry picking tasks on Rosetta Code (www.rosettacode.org). I took a quick look at: * http://rosettacode.org/wiki/Category:Tcl and * http://rosettacode.org/wiki/Category:Racket And they both have the line: The following 845 pages are in this category, out of 845 total. I *think* that means that both Tcl and Racket have 845 tasks impemented, but short of walking down a printout with a pen (and it's far to late to be doing that) -- I do believe that Tcl and Racket are now jointly the most popular programming languages on Rosetta Code. WELL DONE AND THANKS TO EVERYONE WHO HAS CONTRIBUTED (especially Racket) CODE ONTO ROSETTA CODE! And many, many thanks to the Racket team for producing a language which is now demonstrably as competent as any. (Although we all knew that before anyway, didn't we?) Tim -- 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. -- -- Jens Axel Søgaard -- 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] performance with freeze from 2htdp/image on very complex images
On May 4, 2015, at 6:02 PM, Robby Findler ro...@eecs.northwestern.edu wrote: Another approach here would be to help me do performance debugging of 2htdp/image :). You could write the code directly as imperative calls to the dc% interface and see how that compares. If there's a significant difference, that suggests we might be able to find a way to speed up 2htdp/image. I tried doing that, and here’s what I got: (time (snowflake/inner-fractal 728)) : cpu time: 14775 real time: 14874 gc time: 2304 (time (freeze img1)) : cpu time: 377110 real time: 377867 gc time: 198343 (time (snowflake/inner-fractal/draw 728)) : cpu time: 24257 real time: 24267 gc time: 5852 Where snowflake/inner-fractal uses 2htdp/image, the result of that call is defined as img1, and snowflake/inner-fractal/draw uses racket/draw. The program that produces this output is here: https://github.com/AlexKnauth/koch-snowflake/blob/master/try-draw/time.rkt -- You received this message because you are subscribed to the Google Groups Racket Users group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] Re: scribble namespace landgrab embedded package documentation
Clarification: This is not a proposed official documentation format; this is an optional thing, for package authors who choose to use my forthcoming unofficial tool. I'm just making sure that these Scribble names will be OK. Neil Van Dyke wrote on 05/04/2015 07:39 PM: For purposes of embedding docs for a package in its Racket source file(s), anyone care whether I landgrab some names in the Scribble namespace (for package metadata)? I'm thinking the names will generally one-word generic terms, but with capitalization. Example package source file with said metadata: BEGIN #lang racket/base ;;; @Package{duckling} ;;; @Version{0.1} ;;; @Subtitle{Small-Footprint Web Server in Racket} ;;; @Author{Neil Van Dyke} ;;; @Author{Alyssa P. Hacker} ;;; @License{LGPLv3} ;;; @Legal{Copyright 2015 Neil Van Dyke. This program is Free Software; ;;; you can redistribute it and/or modify it under the terms of the ;;; GNU Lesser General Public License as published by the Free ;;; Software Foundation; either version 3 of the License, or (at your ;;; option) any later version. This program is distributed in the ;;; hope that it will be useful, but without any warranty; without ;;; even the implied warranty of merchantability or fitness for a ;;; particular purpose. See http://www.gnu.org/licenses/ for details. ;;; For other licenses and consulting, please contact the author.} (require (for-syntax racket/base)) ;;; @section{Introduction} [CODE INTERSPERSED WITH THREE-SEMICOLON SCRIBBLE GOES HERE] ;;; @History{ ;;; ;;; @Release[0.1 2014-12-31]{ ;;; Initial release.} ;;; } END Rationale: * I'm thinking of using the Racket reader for metadata, instead of some special-cased text kludge for the metadata, for simplicity/elegance of implementation. * I'm using three-semicolon comments instead of McFly's `doc` forms, to simplify evaluation, and to make visually distinguishing between doc and code easier without special editor support. * I've moved the metadata from `info.rkt` back into source file, to make only one file you have to edit per package (the redundant bits of `info.rkt`, like package name and description, can be updated automatically using http://www.neilvandyke.org/racket-progedit/;). Also, when packages were forked under McFly, the legal notice in `mcfly-legal` variable in `info.rkt` tended to get lost, and lawyers like you to put the notice on the actual file anyway (rather than my old ;; See file info.rkt for legal info. kludge comment at the tops of key files). Incidentally, if you paste that example code into Emacs with Quack, you should see remnants of 13-year-old support for my earlier embedded Texinfo format: http://postimg.org/image/wuwy376od/ (Though I preferred the look of comments when they were light blue, like in DrScheme v103, instead of the modern yellow-snow. :) 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.
[racket-users] scribble namespace landgrab embedded package documentation
For purposes of embedding docs for a package in its Racket source file(s), anyone care whether I landgrab some names in the Scribble namespace (for package metadata)? I'm thinking the names will generally one-word generic terms, but with capitalization. Example package source file with said metadata: BEGIN #lang racket/base ;;; @Package{duckling} ;;; @Version{0.1} ;;; @Subtitle{Small-Footprint Web Server in Racket} ;;; @Author{Neil Van Dyke} ;;; @Author{Alyssa P. Hacker} ;;; @License{LGPLv3} ;;; @Legal{Copyright 2015 Neil Van Dyke. This program is Free Software; ;;; you can redistribute it and/or modify it under the terms of the ;;; GNU Lesser General Public License as published by the Free ;;; Software Foundation; either version 3 of the License, or (at your ;;; option) any later version. This program is distributed in the ;;; hope that it will be useful, but without any warranty; without ;;; even the implied warranty of merchantability or fitness for a ;;; particular purpose. See http://www.gnu.org/licenses/ for details. ;;; For other licenses and consulting, please contact the author.} (require (for-syntax racket/base)) ;;; @section{Introduction} [CODE INTERSPERSED WITH THREE-SEMICOLON SCRIBBLE GOES HERE] ;;; @History{ ;;; ;;; @Release[0.1 2014-12-31]{ ;;; Initial release.} ;;; } END Rationale: * I'm thinking of using the Racket reader for metadata, instead of some special-cased text kludge for the metadata, for simplicity/elegance of implementation. * I'm using three-semicolon comments instead of McFly's `doc` forms, to simplify evaluation, and to make visually distinguishing between doc and code easier without special editor support. * I've moved the metadata from `info.rkt` back into source file, to make only one file you have to edit per package (the redundant bits of `info.rkt`, like package name and description, can be updated automatically using http://www.neilvandyke.org/racket-progedit/;). Also, when packages were forked under McFly, the legal notice in `mcfly-legal` variable in `info.rkt` tended to get lost, and lawyers like you to put the notice on the actual file anyway (rather than my old ;; See file info.rkt for legal info. kludge comment at the tops of key files). Incidentally, if you paste that example code into Emacs with Quack, you should see remnants of 13-year-old support for my earlier embedded Texinfo format: http://postimg.org/image/wuwy376od/ (Though I preferred the look of comments when they were light blue, like in DrScheme v103, instead of the modern yellow-snow. :) 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.