Wolfram Mathematica

Welcome! This is the main Mathematica chat room for mathematic...
Jun 12, 2023 14:05
The ones I showed presently work on Firefox and Chromium browsers. They are somewhat fragile as the security rules about clipboard access keep changing, and the page format could change. But they work today.
Jun 12, 2023 14:05
@Nasser "bookmarklet" is just a fancy name for a hyperlink that uses the javascript: protocol. When a browser dereferences the link, it executes the code. To use it, create a new bookmark and set the URL to the content of the bookmarklet. When viewing an MSE page (or any page with PRE tags), and open the bookmark. The bookmarklet will execute without leaving the page.
Jun 11, 2023 20:09
javascript:navigator.clipboard.writeText(window.getSelection().anchorNode.parentNode.closest("pre").innerText)
Jun 11, 2023 20:09
or, to get just the PRE element that contains the current selection (no need to select the entire block):
Jun 11, 2023 20:05
javascript:navigator.clipboard.writeText(Array.from(document.querySelectorAll("pre")).map(b => b.innerText).join("\r\n\r\n/********/\r\n\r\n"))
Jun 11, 2023 20:05
@ydd The following browser bookmarklet will concatenate and copy all code blocks (PRE elements) on the page onto the clipboard:
3
May 6, 2021 02:00
As someone who writes a lot of higher-order functions, the new syntax appears very sweet. But, for me at least, the scoping problem makes it too bitter :)
May 6, 2021 01:59
g[fn_] := {1} /. {b_} :> fn[b]

f[x_] := a |-> a + x
g[f[10]]
(* 11 *)

f[x_] := b |-> b + x    (* uh-oh, "b" is used in "g" *)
g[f[10]]
(* error: Parameter specification 1 in Function[1,10+1] should be a symbol or a list of symbols. *)
May 6, 2021 01:59
@EmilioPisanty It is indeed a terrific syntax improvement... but named Function arguments still have scope problems. I've stuck to slot notation ever since a particularly unpleasant debugging session found this:
Jun 26, 2020 14:12
@Mr.Wizard The precedence table in the code parser that WRI has released on GitHub contains comments which detail discrepancies between the kernel parser and Precedence.
May 25, 2020 14:03
@b3m2a1 I'll have to defer to you judgment on that one... I am frequently criticized on this site for not paying enough attention to performance :) The Condition approach removes some redundant pattern-matching in exchange for other overheads. But unless the expression structure and patterns are particularly simple (and even then), it would be hard for me to predict whether that trade-off is worth it. I would have to benchmark in the context of the real problem.
May 25, 2020 04:35
I meant to say... Cases does not really work with sequences...
May 25, 2020 04:33
Complex patterns must go in the inner $rules. I don't think that restricts the generality of the allowable patterns beyond the restrictions that Cases already places upon its patterns, but maybe you have found an example.
May 25, 2020 04:33
@CATrevillian Cases does really work with sequences even where there is only a single rule. It always inspects individual elements even when given sequence patterns and level specs. In the form I gave, it is crucial that the outer pattern i_ match everything so that Condition can do its work.
May 24, 2020 20:06
$rules = {n_?PrimeQ :> prime[n], n_?PerfectNumberQ :> perfect[n], _ -> $Failed};

Range[10] // Cases[i_ :> With[{r = i /. $rules}, r /; r =!= $Failed]]

(* {prime[2],prime[3],prime[5],perfect[6],prime[7]} *)
May 24, 2020 20:06
@CATrevillian If we add an explicit "failure" value to our rules, then we can write something like this:
May 13, 2020 17:59
@CATrevillian The Import will only return the selected elements. However, I cannot speak to whether the internal implementation will do this by streaming the notebook or by reading the entire thing into memory. Some experimentation and/or spelunking would be required.
May 13, 2020 14:50
In particular, the function tutorialType defined in that response can, despite the name, determine the type of any documentation page.
May 13, 2020 14:50
14
A: How can I list all tech note pages?

WReachThe old documentation center used to have index pages for things like tech notes, but that seems to be absent in version 12.1. But until they reappear... "Tech note" in 12.1 is not so much a first-class concept as it is a qualifier applied to tutorials. Tutorial types are identified by a certa...

May 13, 2020 14:50
@CATrevillian If you are using V12.1 then the method listed here could be adapted to inspect any documentation page, not just tutorials:
Apr 18, 2020 03:05
14
Q: How to invite users to a Stack Overflow chat group?

Rajesh LoganathanI have created a new chat group. Is it possible to invite related developers to my chat group? Is there any option to invite developers into a chat group? I have recently created the chat group.

Apr 18, 2020 03:05
@JimB These instructions are for StackOverflow, but it is basically the same here:
Apr 8, 2020 02:15
@ChrisK Yikes, I fell into that trap. My mind thinks frustum by my finger muscle memory types frustrum @Silvia: please take note: it is "frustum".
Apr 8, 2020 01:17
@Silvia A very formal name for the bottom part is frustrum. In this case it would be an oblique frustrum whereas it would have been a right frustrum if the cut were parallel to the base. The other part would be the apical part, that is, "the part next to the apex". I have not heard of a simple name for this part.
2
Mar 16, 2020 14:54
@xzczd The documentation center has been updated for v12.1 as well.
4
Feb 24, 2020 17:51
The mapping back then was essentially what you suggest. But I suppose at some point ater the ctrl key was introduced they decided to use it for cross-platform consistency (as opposed to Mac-only consistency).
Feb 24, 2020 17:42
@LukasLang For many years neither the Lisa nor Mac keyboards had control keys. Ancient history now, though.
Dec 28, 2019 17:27
Such redirection is a bit hacky since stderr and stdout messages might be interleaved somewhat randomly. But it works reasonably well in interactive contexts where we are just interested in whether and how things might have failed.
Dec 28, 2019 17:25
As for the syntax "2>&1", this is not a Mathematica feature but rather a command shell feature supported by many shells (both on Unix and Windows). It indicates that the stderr stream (channel 2) is to be redirected to the stdout stream (channel 1). This way, any error messages get captured by the Import as well.
Dec 28, 2019 17:23
I use Import["!command", "Text"] to get the output as a single sting without any further interpretation.
Dec 28, 2019 17:23
@PlatoManiac As described in Streams and Low-Level Input and Output, if we prefix an input stream name with an exclamation mark then the stream data will be the output that results from executing the command that follows the exclamation mark. We can use any input operation: Read, ReadList, Get, Import, etc.
Dec 28, 2019 06:09
@LeonidShifrin Thanks for all the comments on the EntityFramework question. When I logged in and saw seven comments my first thought was, "Boy, I must have really fouled up that response" :) I have made some minor revisions to avoid implying that compilable query operators can only be used for filtering. But I hope you will forgive me for not trying to incorporate more of your observations into an already TL;DR answer :)
Nov 2, 2019 01:30
@anhnha If you are keen to learn all the gnarly details about the evaluation process, then I suggest reading Chapter 7 of Wagner's Power Programming with Mathematica, especially section 7.1.3. You can find a link to a free download in the answer (22724).
Oct 15, 2019 15:29
@Szabolcs The datasets have different types -- try evaluating Dataset`GetType /@ {ds1, ds2}. Dataset type is sensitive to the history of evaluations that created the dataset. See for example (146177).
Oct 15, 2019 15:18
@chuy @Szabolcs also dataset[All, {"a" -> Curry[Divide][dataset[Norm, "a"]]}]
Aug 19, 2019 20:49
@halirutan How about 2x / 3y - 1 /. {x -> 9, y -> 2}, classic bane of beginning algebra students everywhere.
Jun 7, 2019 23:31
You might take into consideration things like which answer has the best explanation (for posterity), or which has the clearest or most concise code, or is the fastest, or uses the least memory. If everything else is equal, you can always choose the one posted first. In any event, it is common practice to upvote every useful answer, whether accepted or not.
Jun 7, 2019 23:31
@MarkRoss You can only accept a single answer. Choose the one you like best. I know that can sometimes be difficult when there are multiple answers, but that is the way it is.
May 22, 2019 23:11
@halirutan I think it is a hold-over from an old trick used to embed Javascript (and by extension, JSON) within HTML script tags. example.
Jan 26, 2019 19:34
my pleasure... or perhaps "Пожалуйста"
Jan 26, 2019 19:31
@VitaliyKaurov try Import["http://lib.ru/INOOLD/OSTEN/gord.txt", CharacterEncoding->"WindowsCyrillic"]
Jan 17, 2019 22:38
@CarlLange +1. I had the same thought when I was watching the various SPARQL/Entity LiveCEOs. A couple of times of I was ready to start shouting it at the screen ;D
Jan 17, 2019 22:34
@Kuba Throw/Catch is explicit and I concur that explicit is good.
Jan 17, 2019 22:30
More like setjmp/longjmp in C.
Jan 17, 2019 22:30
I come from a LISP background so I don't automatically associate Throw/Catch with error handling :)
Jan 17, 2019 22:30
@Kuba I would probably use Return if the exit point was "nearby". For long non-local exits, I would Catch/Throw -- with a localized tag to make sure I don't catch anything by accident. The boundary between the two cases is admittedly vague.
Jan 17, 2019 22:24
Those heuristics have sometimes changed. I know of a specific example where Return was broken for a time in v7 and v8 but fixed in v8.0.4. I've never had a problem with the two-argument form (fingers crossed).
Jan 17, 2019 22:24
@C.E. On the subject of "what is wrong with Return"... the scant documentation documentation says that if the second argument is omitted then the return point will be determined using heuristics.
Jan 3, 2019 23:06
@JoséD. The auto-scaling heuristics have decided to crop the outlier data point on Jan 2. Try DateListPlot[testData, PlotRange -> All].