adrien.k.tateno
2018-8-7 15:01:25

@adrien.k.tateno has joined the channel


lexi.lambda
2018-8-7 17:15:24

@mflatt Can I ask you to take a look at this PR at some point? Or, alternatively, let me know if you think someone else would be better suited to reviewing it? https://github.com/racket/racket/pull/2188


soegaard2
2018-8-7 19:12:35

I am confused by the result of running: #lang racket (define sexp "(define foo 42) (define (bar x) (+ x 1))") (define in (open-input-string sexp)) (file-position in 16) (require syntax-color/racket-lexer) (racket-lexer in) (racket-lexer in) (racket-lexer in) (racket-lexer in) (racket-lexer in) (racket-lexer in)


soegaard2
2018-8-7 19:13:24

The example uses the standard racket-lexer to lex from the beginning of (define (bar x) ...) which is position 16.


soegaard2
2018-8-7 19:13:44

The lexer produces the correct tokens.


soegaard2
2018-8-7 19:14:08

However the start-end positions of the tokens doesn’t start at 16 - they start at 0 ?


soegaard2
2018-8-7 19:14:21

Make that 1 instead of 0.


soegaard2
2018-8-7 19:14:28

What am I missing?


lexi.lambda
2018-8-7 19:20:21

@soegaard2 I believe the internal position counter is distinct from the seek position within the file (which is confusing, and I think I have been confused by it before). Try using set-port-next-location! as well?


lexi.lambda
2018-8-7 19:21:02

You might also want port-count-lines! depending on what you’re doing.


soegaard2
2018-8-7 19:26:01

@lexi.lambda Could be it, but I can’t get the expected result. The lexer still counts from 1. #lang racket (define sexp "(define foo 42) (define (bar x) (+ x 1))") (define in (open-input-string sexp)) (port-count-lines-enabled #t) (file-position in 16) (set-port-next-location! in 1 0 16) (require syntax-color/racket-lexer) (racket-lexer in) (racket-lexer in) (racket-lexer in) (racket-lexer in) (racket-lexer in) (racket-lexer in)


soegaard2
2018-8-7 19:27:36

Ah! (port-count-lines! in)


lexi.lambda
2018-8-7 19:27:44

@soegaard2 You need to use either (port-count-lines! in) or set port-count-lines-enabled to #t before creating the input port (or, more specifically, during the dynamic extent of the port’s creation).


soegaard2
2018-8-7 19:28:14

It’s still a bit odd - I don’t need line numbers.


lexi.lambda
2018-8-7 19:28:29

Yeah, I’m not sure why it wouldn’t respect the position!


soegaard2
2018-8-7 19:28:41

Thanks for the help.


lexi.lambda
2018-8-7 19:29:10

Oh, hm: “If line counting has not been enabled for port or if port is a custom port that defines its own counting function, then set-port-next-location! has no effect.”


soegaard2
2018-8-7 19:29:39

Yes, but file-postion should have an effect.


lexi.lambda
2018-8-7 19:30:31

Well, also see this sentence at the top of that documentation section: “By default, Racket keeps track of the position in a port as the number of bytes that have been read from or written to any port (independent of the read/write position, which is accessed or changed with file-position).”


lexi.lambda
2018-8-7 19:30:47

I’ll be honest, I have no idea why the API works the way it does, and I find it confusing, too, but there’s probably a reason. :)


soegaard2
2018-8-7 19:33:25

Oh - the number of bytes read !. Yeah, then changing the position has no effect.


leif
2018-8-7 20:28:09

@mflatt It looks like pango supports creating fonts from ttf (true type font) files (without them being installed in the user’s fontbook), but it doesn’t look like Racket’s font facilities do that. Is there any particular reason you can’t do it in Racket, or did it just not come up?


leif
2018-8-7 20:29:27

(I ask because I’m tired have having to make sure my users install a font, and would like to embed a ttf font in the slideshow/paper/pict, etc.


mflatt
2018-8-7 20:47:08

@leif The last time I looked into that, there were various obstacles to making it work on all platforms. Things may have changed.


leif
2018-8-7 20:57:20

Mmm…okay.


leif
2018-8-7 20:57:43

I’ll take another look at it in a bit then, thanks.


leif
2018-8-7 20:58:28

(Basically, as it currently stands, I can’t really give coauthors a pict program and assume that they will be able to run it without much effort. :disappointed: So I want to fix that. :slightly_smiling_face: Anyway, thanks.)