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

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]))

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

Yes

And if I reload #lang extension

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

Here is a video

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

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

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

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)])

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

@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

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

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

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

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:

Makes sense.

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

is it for saying “this is a sequence”?

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

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

@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:

Something like:

(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)))

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

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.

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

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

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

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

Ah, okay.


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

because it didn’t find the binding for true

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

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?

I think yes. Here’s my code:
@(require (for-label (only-in sicp true)))
@defmodule[sicp]
@defthing[true boolean?]{
The same as @racket[#t].
}

@sorawee questions:
- If you replace
(for-label (only-in sicp true))
with(for-label sicp)
, does it work? - If you look at the definition of the
sicp
module, does it actually providetrue
?

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
- It does provide
true
, though in ther5rs
it uses(#%provide true)
rather than(provide true)
. I did try switchingsicp
to regular Racket and(provide true)
and if I’m not mistaken, the problem persists.

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

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?

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

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

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

You can’t have two defmodule
s 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)]

Will try, thanks!

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!

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

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)

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

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

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

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

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
.

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.

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

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.