jerome.martin.dev
2019-3-18 10:28:54

Maybe make-procedure-like-transformer? Just kidding :stuck_out_tongue:


oldsin
2019-3-18 12:22:25

I tried to write a color lexer for my #lang, but the lexer always in favour of matching digits (:+ (:/ "09")) than matching as identifier (:: "OP_" (:* (:or "_" (:/ "AZ" "09")))); can anybody tell me where did I go wrong?

The lexer is somewhat like: (define bs-lexer (lexer [(eof) #f] [identifier 'symbol] [digits 'constant] [any-char 'symbol]))


alexknauth
2019-3-18 12:33:00

Does the identifier lexer-abbreviation include identifiers with digits in them?


oldsin
2019-3-18 12:33:18

Yes


oldsin
2019-3-18 12:34:30

And if I reload #lang extension


oldsin
2019-3-18 12:35:11

Or if I type a space in front of each identifier, it will look right


oldsin
2019-3-18 12:44:44

Here is a video


oldsin
2019-3-18 12:58:05
;; brag/support
(define bs-lexer
  (lexer
   [(eof)
    (values lexeme 'eof #f #f #f)]
   ["OP_1234"
    (values lexeme 'symbol #f (pos lexeme-start) (pos lexeme-end))]
   [(:+ (:/ "09"))
    (values lexeme 'constant #f (pos lexeme-start) (pos lexeme-end))]
   [any-char
    (values lexeme 'symbol #f (pos lexeme-start) (pos lexeme-end))]))

(define (color-bs port offset racket-coloring-mode?)
  (define-values (str cat paren start end)
    (bs-lexer port))
  (values str cat paren start end 0 #f))

Here is the exact code I used for my color lexer… I really dont know where did I go wrong


oldsin
2019-3-18 12:58:45

Even I use literal string “OP_1234” to match, it still has the same issue


leif
2019-3-18 13:04:21

@ryanc Is there any easy way to get to a nested syntax-class attribute?


leif
2019-3-18 13:04:35

Something like maybe:

(define-splicing-syntax-class foo
  (pattern (~seq x:id y:id)))
(define-syntax-class bar
  (pattern (a:foo b:foo)))

(define stx #'(q w e r))

(syntax-parse stx
  [that:bar
   #:declare that.a foo
   (attribute that.a.x)])

ryanc
2019-3-18 13:11:42

@leif The Right Way is to add #:attributes (a.x b.x) to the definition of bar. The Sketchy, Deprecated Way is to add #:auto-nested-attributes instead (but then it matters that bar is defined after foo). In both of those cases, you need to delete the #:declare from the use at the bottom. Yet another thing you could do is leave the definitions alone and re-parse the subterm: change the #:declare line to #:with a:foo #'that.a (for example).


jerome.martin.dev
2019-3-18 13:12:57

@ryanc > (syntax-parse stx [that:bar #:with a:foo #'that.a (attribute a.x)]) ; readline-input:61:12: syntax-parse: splicing syntax class not allowed here


leif
2019-3-18 13:13:11

I don’t think I could do #:with a:foo #'that.a, because its a splicing-syntax-class.


leif
2019-3-18 13:13:48

Ya, I get . syntax-parse: splicing syntax class not allowed here in: a:foo with that code.


ryanc
2019-3-18 13:14:38

Ah, then you could do #:with (a:foo) #'that.a, I think. But re-parsing is still not a great way to do it.


leif
2019-3-18 13:15:06

As for adding the #:attributes manually. I’d rather not do that as its then repeating a bunch of the foo syntax class. But if that’s the only way, thanks anyway. :disappointed:


leif
2019-3-18 13:15:23

Makes sense.


jerome.martin.dev
2019-3-18 13:17:11

I wonder why it works if you add parens around the splicing syntax class :thinking_face:


jerome.martin.dev
2019-3-18 13:17:58

is it for saying “this is a sequence”?


ryanc
2019-3-18 13:20:38

Yes, the pattern (a:foo) means match a term whose contents consist of a foo match, followed by nothing else.


ryanc
2019-3-18 13:23:02

For example, a:foo can match the sequence of terms apple orange, so (a:foo) can match the term (apple orange).


leif
2019-3-18 13:24:09

@ryanc Oh geez. So it looks like if I do use the #:attributes field, then I would need to manually specify every single attribute. :confused:


leif
2019-3-18 13:24:35

Something like:


leif
2019-3-18 13:24:38
(define-splicing-syntax-class foo
  (pattern (~seq x:id y:id)))
(define-syntax-class bar
  #:attributes (a b a.x a.y b.x b.y)
  (pattern (a:foo b:foo)))

leif
2019-3-18 13:24:58

Which translate to a rather long list in my actual code. :disappointed:


ryanc
2019-3-18 13:30:22

Yes, syntax-parse does not have a signature abstraction. Or you could use #:auto-nested-attributes if you’re willing to live with the restrictions. Or you could try to move some of the computation into the syntax class definitions to reduce the number of attributes you need to export.


leif
2019-3-18 13:31:52

What do you mean by the ‘syntax class definitions’?


jerome.martin.dev
2019-3-18 13:33:59

something like this maybe: (define-splicing-syntax-class foo (pattern (~seq x:id y:id))) (define-syntax-class bar (pattern (a:foo b:foo) #:with result #'(a.x a.y b.x b.y)))


jerome.martin.dev
2019-3-18 13:34:34

Using the x and y definitions in place instead of passing them down


jerome.martin.dev
2019-3-18 13:38:58

I’m not sure yet it’s a good strategy, but it has served me well so far.


leif
2019-3-18 13:41:14

Ah, okay.


sorawee
2019-3-18 18:16:00

sorawee
2019-3-18 18:17:03

Why is true underlined? Note that it’s my own true, and I did (require (for-label (only-in my-lang true)))


samth
2019-3-18 18:17:53

because it didn’t find the binding for true


sorawee
2019-3-18 18:18:44

But I did require for label… isn’t that supposed to make the binding for true appear?


alexknauth
2019-3-18 18:33:02

You also have a defmodule with my-lang in the same scribble-document, right? Does the way you refer to my-lang in the defmodule match the way you refer to my-lang in the for-label require?


sorawee
2019-3-18 18:37:01

I think yes. Here’s my code:

@(require (for-label (only-in sicp true)))
@defmodule[sicp]
@defthing[true boolean?]{
  The same as @racket[#t].
}

notjack
2019-3-18 18:47:50

@sorawee questions:

  1. If you replace (for-label (only-in sicp true)) with (for-label sicp), does it work?
  2. If you look at the definition of the sicp module, does it actually provide true?

sorawee
2019-3-18 19:09:41
  1. sicp is also a hash lang, so (for-label sicp) creates a bunch of conflict. E.g., module: identifier already required for label at: #%app
  2. It does provide true, though in the r5rs it uses (#%provide true) rather than (provide true). I did try switching sicp to regular Racket and (provide true) and if I’m not mistaken, the problem persists.

sorawee
2019-3-18 19:13:14

If you want to try out the actual code, here it is: https://github.com/sicp-lang/sicp/blob/master/sicp-doc/sicp-manual.scrbl#L4


alexknauth
2019-3-18 19:37:06

Is the true it provides the same one as from racket, or is it a separate binding that happens to produce the same value? Does that matter for scribble documentation links?


sorawee
2019-3-18 19:40:53

No it’s not the same one. It’s defined as (define true #t). I don’t want it to link to Racket documentation.


sorawee
2019-3-18 19:45:07

And I mean, this problem happens with non-Racket identifiers like nil as well.


sorawee
2019-3-18 19:45:57

So I don’t think it’s about how Racket and sicp are conflicted


mflatt
2019-3-18 20:55:16

You can’t have two defmodules in a section. You can use #:multi. Also, since some bindings are provided by both module, use #:use-sources to prefer the more specific one: @defmodule[#:multi (sicp sicp-pict) #:use-sources (sicp-pict)]


sorawee
2019-3-18 21:05:10

Will try, thanks!


oldsin
2019-3-18 21:47:36

Yes, reload #lang extension do work. Is ‘handles backtracking’ refers to setting my backup distance to some value larger than 0? Thanks for the help BTH!


oldsin
2019-3-19 00:05:26

Thanks for the help! That perfectly solves my problem! :fireworks:


mark
2019-3-19 00:49:28

When I make a UI with framework, it doesn’t change the app name in the menu bar or About, and it has an extra status bar with memory, is there a way to fix those? (application:current-app-name kAppName) (set! frame (new frame:standard-menus% [label kAppName] [width kWidth] [height kHeight] [min-width kWidth] [min-height kHeight] [style '(no-resize-border)] )) (set! canvas (new game-canvas% [parent (send frame get-area-container)])) (send frame open-status-line 'status) (send frame update-status-line 'status "Hello, World!") (send frame show #t)


sorawee
2019-3-19 01:11:59

Yup, avoiding two defmodule solves the problem. Thank you again :slightly_smiling_face:


mflatt
2019-3-19 02:14:24

The menu bar and “About” names are taken (by the OS) from the application name, so those will change if you make an executable with raco exe --gui or even raco exe --gui --launcher.

I think the extra status line is because frame:standard-menus% applies frame:standard-menus-mixin to frame:status-line%, but you should be able to apply it to frame:basic%.


mark
2019-3-19 02:17:20

I mostly want the standard menus, tho, maybe I’m not seeing a way to remove a status line?


mflatt
2019-3-19 02:21:57

I mean (new (frame:standard-menus-mixin frame:basic%) ....), which should preserve he menus.


mflatt
2019-3-19 02:22:23

I see that removes open-status-line and update-status-line, so maybe there’s a better choice. Or maybe use the more primitive create-status-line and set-status-text.


mark
2019-3-19 02:23:18

OK, so I am able to make an app with raco that shows correct titles. I’m having library problems now, but I’ll look at that in a bit.


mark
2019-3-19 02:26:26

This worked: (class (frame:standard-menus-mixin (frame:status-line-mixin frame:basic%))


mark
2019-3-19 02:58:38

So, now that’s working, raco exe can’t find rsound: raco exe --gui -l ++lib rsound -o build/Odyssey.app Odyssey.rkt standard-module-name-resolver: collection not found for module path: rsound collection: "rsound" in collection directories: /Users/mdh/Applications/Racket v7.2/collects … The collects flags don’t seem to do anything, neither created a folder or moved any libraries into the app bundle.