mflatt
2022-4-25 17:52:11

I think I finally have the machine repaired and reconfigured. There are still some Minimal Racket failures in the latest build, because I sorted out the last known problem half-way through the build, but it should be ok going forward.


sschwarzer
2022-4-25 21:47:21

I’m trying to define a shorthand in #lang scribble/manual . This works: @(define level-basic "Level: basic") ... @level-basic This works, too: @(define level-basic (bold "Level: basic")) ... @level-basic Now I want to set only “Level” as bold, but not “basic”, i.e. I want the string from @level-basic rendered as

Level: basic

Everything I tried so far didn’t work. How does it work correctly?


sorawee
2022-4-25 21:49:37

Perhaps @elem{@bold{Level:} basic}?


sorawee
2022-4-25 21:50:25

@t{@bold{Level:} basic} could also work, depending on whether you want this thing to be a paragraph or not.


sschwarzer
2022-4-25 21:52:11

@(define level-basic @elem{@bold{Level:} basic}) actually works. :slightly_smiling_face:


sschwarzer
2022-4-25 21:53:21

Yes, I want it to be a paragraph, but for now I’m ok to put an empty line before and after the @level-basic. Maybe later this should become some kind of box or other annotation.


blerner
2022-4-25 21:54:27

In nearly every scribble context that matters, you can return a list, so @(define level-basic (list @bold{Level:} "basic")) should also work, without an extraneous @elem or @t


sorawee
2022-4-25 21:57:32

Personally I like @elem more because it can be easily written without needing to be super careful about spacing (in your code, you lost a space).


sschwarzer
2022-4-25 21:57:38

Yes, that’s better. Thanks!


sorawee
2022-4-25 21:58:21

And I think elem and list are essentially “compatible”?


sschwarzer
2022-4-25 21:59:18

By the way, @(define level-basic (list (bold "Level:") " basic")) works, too.

I had tried this in a similar way, but with string-append instead of list and got a contract violation that (bold "Level:") was an element, not a string.


sschwarzer
2022-4-25 22:00:17

Yes and no. I re-added the space to " basic". :wink:


sschwarzer
2022-4-25 22:01:08

Either way, I see that both approaches are useful.


sschwarzer
2022-4-25 22:06:19

Yes, at least in my case. :slightly_smiling_face:


sschwarzer
2022-4-25 22:18:28

So thanks to both of you!


ben.knoble
2022-4-25 22:18:42

Wouldnt this last still have the issue that (+ 1 b) => (+ 1 undefined) when trying to set a?


sschwarzer
2022-4-25 22:56:40

@ben.knoble I was referring to sorawee and blerner because of their Scribble help.


ben.knoble
2022-4-25 23:44:03

Lol retracted my phone hadnt caught up yet


capfredf
2022-4-26 00:01:42

I have a dump question: is it possible to do a binary search on a sorted list in O(log(n)) time given that almost all list operations take O(n) time? or am I missing something?


capfredf
2022-4-26 00:03:10

Of course, converting a list into something else takes O(n) time


sorawee
2022-4-26 00:04:30

Yes, it’s not possible to binary search on a sorted list in O(log(n)) time.

What you could do, however, is framing the question as

With m search queries, you can use binary search to search a sorted list in O(n + m log n).


sorawee
2022-4-26 00:10:00

So this will slightly help you when e.g. m = sqrt(n) because it takes only O(n + sqrt(n) log n) = O(n)

If the list is unsorted, then it would take O(n log n + sqrt(n) log n) = O(n log n). Slightly worse.


capfredf
2022-4-26 00:13:51

thanks for the input. I have a question: isn’t that m = log n in the worst-case scenario?


sorawee
2022-4-26 00:15:30

What do you mean by “the worst-case scenario”?


sorawee
2022-4-26 00:16:11

Are you talking about what I wrote “this will slightly help you when e.g. m = sqrt(n)“?


sorawee
2022-4-26 00:28:14

Let’s consider many scenarios:


m = 1

Linear search works better here with or without pre-sorting. They are both O(n).


m = log n

With pre-sorting, you can convert to vector in O(n) and binary search, taking O(n) in total.

Without pre-sorting, you can just linear search for m times, taking O(n log n) in total.


m = sqrt n

With pre-sorting, you can convert to vector in O(n) and binary search, taking O(n + sqrt(n) log n) = O(n) in total.

Without pre-sorting, this is where it’s worthwhile to pay the “sorting fee” of O(n log n).


m = n

With pre-sorting, O(n log n)

Without pre-sorting, sort it first. Also O(n log n).


capfredf
2022-4-26 00:45:31

Oh, I see. I misread your question


capfredf
2022-4-26 00:45:44

Thanks for the detailed explanation


sorawee
2022-4-26 00:49:13

m = n / log n is another interesting case.


capfredf
2022-4-26 01:16:24

why is it interesting?


sorawee
2022-4-26 01:17:30

It seems intuitively the largest m where pre-sorting maintains an advantage over non pre-sorting


sorawee
2022-4-26 01:17:36

I could be wrong though


soegaard2
2022-4-26 06:18:33

You are right. I should have tested that snippet before posting. Turns out I it didn’t behave the way I was expecting.

Before undefined found its place in racket/undefined a trick to produce the undefined values was used. The result of (letrec ([x x]) x) evaluated to undefined. Now it throws an error stating that the variable x is referenced before it is bound. For some reason I thought it was a general thing and not limited to letrec.