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.
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?
Perhaps @elem{@bold{Level:} basic}
?
@t{@bold{Level:} basic}
could also work, depending on whether you want this thing to be a paragraph or not.
@(define level-basic @elem{@bold{Level:} basic})
actually works. :slightly_smiling_face:
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.
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
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).
Yes, that’s better. Thanks!
And I think elem
and list
are essentially “compatible”?
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.
Yes and no. I re-added the space to " basic". :wink:
Either way, I see that both approaches are useful.
Yes, at least in my case. :slightly_smiling_face:
So thanks to both of you!
Wouldnt this last still have the issue that (+ 1 b)
=> (+ 1 undefined)
when trying to set a?
@ben.knoble I was referring to sorawee and blerner because of their Scribble help.
Lol retracted my phone hadnt caught up yet
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?
Of course, converting a list into something else takes O(n) time
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).
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.
thanks for the input. I have a question: isn’t that m = log n in the worst-case scenario?
What do you mean by “the worst-case scenario”?
Are you talking about what I wrote “this will slightly help you when e.g. m = sqrt(n)“?
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).
Oh, I see. I misread your question
Thanks for the detailed explanation
m = n / log n is another interesting case.
why is it interesting?
It seems intuitively the largest m where pre-sorting maintains an advantage over non pre-sorting
I could be wrong though
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
.