Re: [racket-users] Racket (or Scheme) macros for C
On Tue, Jul 04, 2017 at 01:52:41PM -0700, spearman wrote: > I have built up a good toolchain for C programming including static analysis > and runtime testing tools, but I find the C preprocessor is really lacking > for metaprogramming facilities. > > Here is an implementation of "Lisp" macros for C: > https://github.com/eudoxia0/cmacro > > It doesn't seem to be actively maintained and a bit buggy (weird formatting > errors), and, well, it's Common Lisp :\ > > I made a start on converting the above into Racket: > > https://github.com/spearman/rcmacro > > At this point it is little more than a main module with command-line options > and stubs for the rest of the implementation. > > Two sticking points so far are error handling and finding a replacement for > the "packrat parser" (esrap) that cmacro relies on, as highlighted here: > https://github.com/eudoxia0/cmacro/blob/master/src/parser.lisp#L290 > > If there is something available for Racket along the same lines as esrap, > which uses TDPL grammar, I may be able to move forward with adapting this > code, otherwise it might be a lost cause and better off just coming up with > something from scratch (and I might learn something in the process). However > it seems like a large task and I would be essentially starting from first > principles. > > Before I make a choice on whether to proceed, I wanted check first if there > are already any Racket-based (or Scheme-based!) implementations of macros for > C. > There is this Racket implementation for C++: > > https://github.com/elfprince13/RacketMacros4Cxx > > but it requires a custom llvm/clang build, and the "demos" don't look very > much like what I had in mind. Not exactly what you're asking for, but Gambit is a Scheme implementation that compiles to C (or C++). You can define functions and specify what C ode should be used to implement them. So in a sense, mcros in Gambit end up generating C code. -- 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. For more options, visit https://groups.google.com/d/optout.
[racket-users] Racket (or Scheme) macros for C
I have built up a good toolchain for C programming including static analysis and runtime testing tools, but I find the C preprocessor is really lacking for metaprogramming facilities. Here is an implementation of "Lisp" macros for C: https://github.com/eudoxia0/cmacro It doesn't seem to be actively maintained and a bit buggy (weird formatting errors), and, well, it's Common Lisp :\ I made a start on converting the above into Racket: https://github.com/spearman/rcmacro At this point it is little more than a main module with command-line options and stubs for the rest of the implementation. Two sticking points so far are error handling and finding a replacement for the "packrat parser" (esrap) that cmacro relies on, as highlighted here: https://github.com/eudoxia0/cmacro/blob/master/src/parser.lisp#L290 If there is something available for Racket along the same lines as esrap, which uses TDPL grammar, I may be able to move forward with adapting this code, otherwise it might be a lost cause and better off just coming up with something from scratch (and I might learn something in the process). However it seems like a large task and I would be essentially starting from first principles. Before I make a choice on whether to proceed, I wanted check first if there are already any Racket-based (or Scheme-based!) implementations of macros for C. There is this Racket implementation for C++: https://github.com/elfprince13/RacketMacros4Cxx but it requires a custom llvm/clang build, and the "demos" don't look very much like what I had in mind. Mostly what I am looking for is a Scheme-like "macro-by-example" syntax to provide some level of syntactic information (and hopefully hygiene) above what the C preprocessor gives, but not necessarily full-blown "cooperating" (MTWT) Racket macros. Comments/suggestions are appreciated. -- 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] Forwarding syntax or srcloc
I'd like to be able to get source location information from behind two or more layers of macros. I have a macro, call it mk-data, whose job it is to make an internal data structure. Among other things, it records a srcloc for later tracking. In another module, I have another macro whose job it is to specialize mk-data and present a simpler interface. Unfortunately, the srcloc that gets stored ends up being the location of the simplifying macro. Not what I want. I need to somehow forward the srcloc of its use-location. Example follows: a.rkt: #lang racket (provide mk-data getloc) (struct data-internal (name x y srcloc) #:guard (λ (n x y srcloc struct-name) (unless (real? x) (raise-argument-error 'data-internal "real?" x)) (unless (real? y) (raise-argument-error 'data-internal "real?" y)) (values n x y srcloc))) (define-syntax (mk-data stx) (syntax-case stx () [(_ name x y) #`(data-internal name x y (srcloc #,(syntax-source stx) #,(syntax-line stx) #,(syntax-column stx) #,(syntax-position stx) #,(syntax-span stx)))])) (define (getloc d) (srcloc->string (data-internal-srcloc d))) b.rkt: #lang racket (provide simple-data) (require "a.rkt") (define-syntax (simple-data stx) (syntax-case stx () [(_ name x) #'(mk-data 'name x 42)])) c.rkt: #lang racket (require "a.rkt" "b.rkt") (getloc (simple-data unlucky 262)) I want the result in c.rkt to be "c.rkt:3:9" or so, rather than "b.rkt:7:7". I realize I could probably make the simple-data macro in b.rkt a bit more sophisticated to help matters, but I'm really resisting doing so. There are going to be a lot of macros like simple-data, and some of them may be written by users, so I'd like to make it as simple as possible to make new ones. I'd rather change mk-data, even if it means making it significantly more complex. What's the best way to accomplish this? -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] Re: beating java (speed)
On Tue, 4 Jul 2017 12:17:12 -0700 (PDT), "'Shakin Billy' via Racket Users"wrote: >i couldn't make the inlining via define-syntax-rule work in typed racket. in >normal racket define-inline did'nt speed things up much but changing the code >of "acht-teiler" to: >CODE-- >(define-syntax-rule (acht-teiler n) > (let loop ((i 2) (count 0) (quadrat 4) (steigung 5)) >(cond ((= quadrat n) #f) > ((> quadrat n) (unsafe-fx= count 3)) > ((unsafe-fx= (unsafe-fxmodulo n i) 0) (loop (unsafe-fx+ i 1) > (unsafe-fx+ count 1) (unsafe-fx+ quadrat steigung) (unsafe-fx+ steigung 2))) > (else (loop (unsafe-fx+ 1 i) count (unsafe-fx+ quadrat steigung) > (unsafe-fx+ steigung 2) > (loop 2 0 4 5) > ) >--CODE >that is: no inner define but a let brought the same speed up as using >typed-racket > >is let in general faster than define? According to the docs, an internal define expands into a letrec form. letrec introduces a set!-able binding whereas named-let (effectively) just creates looping code. I am not familiar with the guts of the current compiler, but I can see how they could be treated very differently. https://docs.racket-lang.org/reference/syntax-model.html?q=define%20internal#%28part._intdef-body%29 >@ gneuner2 >jitting the function with a previous call yields only slightly better results >(on my mashine in the range of milliseconds) That's to be expected given that the program is so small. As I understand it, the current JIT implementation does little or no optimization, so it is straightforward and very fast. The point to remember is that JIT is done incrementally, adding some overhead to the 1st call of each function. To get accurate timings, you need to have exercised all the functions in the call chain at least once. George -- 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: beating java (speed)
i couldn't make the inlining via define-syntax-rule work in typed racket. in normal racket define-inline did'nt speed things up much but changing the code of "acht-teiler" to: CODE-- (define-syntax-rule (acht-teiler n) (let loop ((i 2) (count 0) (quadrat 4) (steigung 5)) (cond ((= quadrat n) #f) ((> quadrat n) (unsafe-fx= count 3)) ((unsafe-fx= (unsafe-fxmodulo n i) 0) (loop (unsafe-fx+ i 1) (unsafe-fx+ count 1) (unsafe-fx+ quadrat steigung) (unsafe-fx+ steigung 2))) (else (loop (unsafe-fx+ 1 i) count (unsafe-fx+ quadrat steigung) (unsafe-fx+ steigung 2) (loop 2 0 4 5) ) --CODE that is: no inner define but a let brought the same speed up as using typed-racket is let in general faster than define? @ gneuner2 jitting the function with a previous call yields only slightly better results (on my mashine in the range of milliseconds) -- 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] Hint on opening enclosing directory of current file from DrRacket
IIRC on windows, at the cmd prompt (and hence maybe through DrR's "system" procedure) you can type "explorer ." to obtain the same behavior. Cheers, Jordan > On Jun 28, 2017, at 5:38 PM, Jameswrote: > > >> On Jun 28, 2017, at 5:42 PM, Glenn Hoetker wrote: >> >> Caveats: 1. Since CWD is set to the most recently run file, you have to have >> run the file whose enclosing directory you wish to open. The default appears >> to the home directory. 2. I know this works on MacOS. I can't see why it >> wouldn't work on Unix systems. Windows scares me, so I have idea if it would >> work there. > > The open command, as such, is Mac specific. The "." argument to open tells > it to open the current working directory but you can specify any folder or > file to open. In Debian, the xdg-open command is very similar. > > -- > 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] Error when codesigning Racket created executable - codesign_allocate: file not in an order that can be processed
Seamus, hello. On 3 Jul 2017, at 23:17, Seamus Brady wrote: I got a bit further than Norman :) Well done! I've added to the Stackoverflow question, a pointer to this discussion. The trick from Matthew did the trick and that Racket based app gets signed and passes all the local GateKeeper checks :) Great stuff. Great stuff indeed. All the best, Norman -- Norman Gray : https://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.
[racket-users] Question about text% undo and on-change
I have to integrate the undo/redo functionality of text% into a custom undo/redo system, because in my application nearly everything is undoable. Basically I need a reliable way to intercept and track the text%'s undo additions, so I can add an undoer to my undo system whenever text% adds an internal undoer. But how? If I understand this correctly, on-change tracks *all* changes character by character, but the automatic undo handling pushes one undoer for several edit operations on the undo stack as it should. I can't find a method for tracker the internal undoer in text% that can be augmented or overriden. Something like on-undo-add. Am I missing something? Best, Erich -- 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] Error when codesigning Racket created executable - codesign_allocate: file not in an order that can be processed
I'm in the process of building a commercial application for Racket, so this is really good to know. Thank you, Seamus -- this would have had me tearing my hair out. Dave PS: I read through this entire thread, understanding the information and the references and finding it useful, while simultaneously wondering why you were talking about codesigning code and who was designing it with you. I literally just realized as I started to type this that you're saying "code signing" not "co-designing". On Mon, Jul 3, 2017 at 6:17 PM, Seamus Bradywrote: > On Monday, 3 July 2017 15:18:07 UTC+1, Matthew Flatt wrote: > > At Mon, 3 Jul 2017 08:15:38 -0600, Matthew Flatt wrote: > > > to make progress for now, you can > > > change > > > > > > collects/compiler/private/mach-o.rkt > > > > > > and replace the call on line 164 to `detect-linkedit-padding` with the > > > constant 12 --- since 12 seems to be the right number for the v6.9 > > > build, but `detect-linkedit-padding` thinks it's 8. > > > > Make that 4 instead of 12 if you're using `raco exe --gui`. > > Thank you Matthew and Norman for taking the time to reply. I got a bit > further than Norman :) > > The trick from Matthew did the trick and that Racket based app gets signed > and passes all the local GateKeeper checks :) Great stuff. This means that > I get create a commercial grade application using Racket - I am delighted. > Thank you, thank you. > > As some extra feedback that may be useful to other readers, I also had to > edit the app slightly to conform to Apples latest app guidelines: > > https://developer.apple.com/library/content/documentation/ > MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html > > I needed to add Resources folder and an Info.plist with the correct > CFBundleIdentifier set for the Racket Framework: > > > http://www.apple.com/DTDs/PropertyList-1.0.dtd;> > > > CFBundleDevelopmentRegion > English > CFBundleExecutable > Racket > CFBundleIdentifier > org.racket-lang.Racket > CFBundleIconFile > Starter > CFBundleInfoDictionaryVersion > 6.0 > CFBundlePackageType > APPL > CFBundleSignature > MrSt > CFBundleVersion > 6.9 > CFBundleShortVersionString > 6.9 > NSPrincipalClass > NSApplicationMain > NSHighResolutionCapable > > NSSupportsAutomaticGraphicsSwitching > > > > > Then I updated the framework folders using the bash script below so that > they conform to the new folder structure as outlined in the Apple docs: > > cd ..app/Contents/Frameworks/Racket.framework/Versions/ > ln -s ./6.9_3m Current > cd ./.app/Contents/Frameworks/Racket.framework/ > ln -s ./Versions/Current/Racket Racket > ln -s ./Versions/Current/Resources Resources > > Then I signed the app using the codesign utility as outlined below: > > https://successfulsoftware.net/2012/08/30/how-to-sign- > your-mac-os-x-app-for-gatekeeper/ > > I hope that helps. Again, many thanks. I am very grateful to get this > working. I would have lost weeks ot work otherwise! > > Regards > > Seamus > > -- > 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] Raising multiple exceptions at once
Stack traces are printed by the default error display handler, as opposed to being part of the exception string. So, you can convert an exception `e` to the form that prints by default by calling the error display handler directly: (with-output-to-string (lambda () (parameterize ([current-error-port (current-output-port)]) ((error-display-handler) (exn-message e) e At Mon, 3 Jul 2017 23:19:35 -0700 (PDT), reilithion wrote: > Hi, > > I have a program that uses multiple threads and may have several exceptions > happen more-or-less at once. I'd like to be able to raise them all together > and have all of them printed to stderr, including stack traces. > > I first tried just throwing them in a list and raising the list, but of > course > that doesn't come out very pretty (only one thread failed in this example): > > uncaught exception: (list (exn:fail:task-failed "I failed.\n" > # ...)) > > Next, I thought I'd try looping through the exceptions and using exn->string. > But it seems this function doesn't give me stack traces or any kind of source > location information. > > It occurred to me to try to use the same mechanism that the REPL does, but I > don't know anything about it, and I found the documentation on prompts and > aborts to be a bit confusing. I didn't grok how the REPL used them to pull > off > its magic trick. What's the right way to go about this? > > Thanks, > Lucas > > -- > 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] Raising multiple exceptions at once
Hi, I have a program that uses multiple threads and may have several exceptions happen more-or-less at once. I'd like to be able to raise them all together and have all of them printed to stderr, including stack traces. I first tried just throwing them in a list and raising the list, but of course that doesn't come out very pretty (only one thread failed in this example): uncaught exception: (list (exn:fail:task-failed "I failed.\n" # ...)) Next, I thought I'd try looping through the exceptions and using exn->string. But it seems this function doesn't give me stack traces or any kind of source location information. It occurred to me to try to use the same mechanism that the REPL does, but I don't know anything about it, and I found the documentation on prompts and aborts to be a bit confusing. I didn't grok how the REPL used them to pull off its magic trick. What's the right way to go about this? Thanks, Lucas -- 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.