« first day (1850 days earlier)      last day (2651 days later) » 

2:27 AM
You know how functions like Sort take an expression and a variable which it operates with? How do you implement that functionality in your own function?
What I'm trying to do is write a function f that takes an expression and two variable names, then returns the expression with the given variables swapped with each other.
@Pavel In the easiest case, you can do this:
swap[expr_, s1_Symbol, s2_Symbol] := expr /. {s1 -> s2, s2 -> s1}
Ok, but in the general case, how do I manipulate variables in an expression given their names?
but beware that you might want to use variables that are assigned to values. Then, this approach might fail.
Thanks btw
In[73]:= swap[x^3 + 3*x^2*Sqrt[y] + 3*x*y + y^(3/2), x, y]

Out[73]= x^(3/2) + 3 x y + 3 Sqrt[x] y^2 + y^3
@Pavel In general it is a bit tricky to not run into problems.
There, you have to work with Hold, Unevaluated, HoldPattern and friends.
But it depends on your particular use-case.
2:39 AM
Got it, I'm a bit new to Mathematica.
I'll look those functions up
Is the /. notation just replacement or can you do other things with it?
@Pavel Yes it is the operator for ReplaceAll
Ok. Thanks a lot!
7 hours later…
9:45 AM
@LeonidShifrin You not only write objectively excellent answers, you write them in a way that appeals to many people as evidenced by your collection of Guru badges. I wonder if you could offer me some advice on how to improve my style. For example I put quite a bit of work into this answer yet it has only received six votes in the last ~2 years:
A: How to check the style and number of arguments like the built-in functions?

Mr.WizardI have moved the large addendum from my answer to How to program a F::argx message? to this post as I believe it is a better fit here. Please see that link for basic information before continuing. Handling multiple messages with an auxiliary function For full control of Message generation wh...

How might you have written this differently? Do you think I am correct in suspecting that it is my presentation rather than factual content that is lacking in this particular case?
10:09 AM
@Mr.Wizard steal Leonid's avatar and change your nick to LeonidShifirin
@Mr.Wizard jokes aside, I don't think your style is a problem, the question itself isn't very popular so people didn't even get to the answer probably.
@Mr.Wizard take a look at ratio answer votes to question votes
same here and same in Leonid's guru answers
10:30 AM
@Kuba Hm... maybe you're right. I know he has his "duds" too (from a vote perspective) but I feel as though Leonid is able to elevate topics in a way I am not however.
A: How to use classical data structure in Mathematica

alancalvittiHere'a quad-tree index (trie) illustrating the compact codes and efficiency enabled by nested Associations and recursive Queries - no looping, no NestWhile or Fold is used. Compare to earlier implementations, eg here. Also addresses "can a Trie be implemented efficiently?" Included are timing ...

10:44 AM
@Szabolcs Mine was vote #1 on that. :)
1 hour later…
12:05 PM
@Mr.Wizard @Leonid I too believe that it is not your style. For one, Leonid almost exclusively writes answers on topics he has a very deep knowledge of. He spent a vast amount of time on meta-programming and how it can be used to make your own code maintainable. In addition to this, it helps to create things like LetL (if I remember correctly). For this, he had to go through a lot of pain understanding the details of e.g. dynamic and lexical scoping.
The key point is that these topics are of interest for a lot of people. This is why most of his great answers have a large amount upvotes in the question as well. What I usually see in Leonids answers is that he takes a small detail and explains it great depth.
On the other hand, you cannot dismiss the differences: Leonid writes maybe one answer a month. You, on the other hand, often write several answers a day. The likelihood that a particular answer of yours that you care about doesn't receive as much attention as you had hoped is larger.
1 hour later…
1:29 PM
Seasonality indexation with the Wolfram Language
1 hour later…
2:49 PM
@Mr.Wizard Well, thanks :) I think that @halirutan made some very good points - I indeed tend to focus on things that personally interest me (or were of interest to me in the past), and try to explain them as thoroughly as I am able to. Which also means that I typically only answer those questions which are of interest to me and where I believe that I understand them reasonably well / deep. If I would broaden out, I would probably find myself in the same situation you are describing.
@Mr.Wizard I actually think that you have a unique answering style that is under-appreciated, perhaps due to the SE voting model. It is great that you do what you do, because your answers are very clear, easy to read and understand, yet deep, and generally provide just what people need most of the time. In a way, though, SE model reflects that, because you are #1 on the site for a reason.
@Mr.Wizard One other thing that might be different for our approaches to answering is that since I am interested in other PLs as well, I often try to view questions from a broader programming perspective, and frequently trying to think of how I would approach some problem in another PL gives interesting angles even for answers on purely Mathematica - related topics.
@halirutan Thanks man, I am somewhat flattered by your description. But I am happy too, because that's what I was actually trying to achieve with my answers. Also at this time, getting such responses is very reassuring, because I've been questioning my M abilities for some time now, due to a number of reasons. Also, posting an answer once per month isn't something I am happy about - it wasn't like that before and hopefully I will get back to more frequent answering some time soon.
@Mr.Wizard In any case, my summary would be that I think that your answering style is very valuable and I'd just keep doing what you do, since this is of great help to the community - even if this is not always reflected by the votes. Also, one thing I realized is that you can't compare absolute vote numbers for different questions / answers to them - just because different topics may attract people very differently (which is what @Kuba has rightly noted).
3:17 PM
@Kuba - just to take it into chat, I still think Overlay is to be avoided at almost all costs, and that the accepted answer to that question is outdated, but I guess it's just my preference
also deleted that comment as it's not good form to badtalk another's answers
3:40 PM
@Mr.Wizard I think Kuba is correct here, the question wasn't noticed. In fact, I didn't notice it until you mentioned it. My time on here is more limited than I would like and that adds to me missing some interesting things. That said, I upvoted the answer where some of the info was originally posted, so to me, it was at least mostly covered elsewhere.
Q: Retroactively adding new tags to questions

Chris KI added a new tag today on one of my questions, based on the subject matter ("ecology", similar to the "physics" and "chemistry" tags that already exist). I'm considering adding this tag to previous questions that it fits. Is this: a good idea a bad idea a waste of time because no one cares ab...

4:14 PM
@JasonB I didn't like Overlay to start with. But there is no documented alternative. It is great the more undocumented but heavily used functions are advertised lately but they are still undocumented.
@JasonB don't worry about badtalk if it is constructive :)
2 hours later…
6:02 PM
Can anybody teach me?
When I try to call the Imgur API,it will give me a response like "Imgur is temporarily over capacity. Please try again later."Would you be like this?
This is my code:
img = Image[Plot[Sin[x], {x, 0, 6 Pi}]];
"https://api.imgur.com/3/image", <|"Method" -> "POST",
"Parameters" -> {"key" ->
"image" -> img}|>], "Body"], "RawJSON"]
@halirutan Help ;)
6:36 PM
As your answer [here](http://mathematica.stackexchange.com/a/807/21532) , I write a code like:`img = Image[
Plot[Sin[x], {x, 0,
6 Pi}]]; Import["https://api.imgur.com/3/image", "XML",
"Method" -> "POST",
"Parameters" -> {"key" ->
"image" -> img}]`
Can you update you code for version 11 and API of version 3?
7:09 PM
@yode - you might have some luck looking at the code for the SE uploader palette here
or also I've found @J.M. to be a true HTTP-POST wizard
@JasonB God,I have to say I'm lost in his 1000 lines of code
And it looks like he uses java to do some of the work
apparently so did Szabolcs in the first incarnation of the palette here: github.com/szhorvat/SEUploader/blob/master/ImageUploader.m
are you trying to upload an image from a notebook to your own account in imgur? (still having great firewall problems?)
The current key is from myself account
@JasonB And I'm in out of firewall now. :)
Can you call that upload-API with your own account now?
As your link above,Szabolcs is uploading image with JAVA,too.
7:31 PM
this may help, not sure
Q: How do you submit an Input type of "file" using URLExecute?

Simon O'DohertyI have to submit a form like as follows: <input type="file" name="jpgFile"> I can't seem to find any instructions on sending this in URLExecute. If I specify the file name as the parameter it fails. If I try Import[filename, "JPG"] of the image it also fails as invalid. I thought his might ...

7:57 PM
@Kuba @halirutan @Leonid @rcollyer Thank you all for your input. Just to be clear I am not complaining about a general lack of votes; I think my answers get plenty of votes, sometimes more than they deserve. I saw/see message generation as a topic of wide interest so I assumed that answer would be more popular if it were well written, since I tried to make it a reference post on the subject.
8:11 PM
@yode The 1000 lines of Mathematica code don't do anything. The hard work of uploading is done by a tiny java call.
@yode Please look here. This function takes a byte[] which is the content of the png image and uploads it to SE.
@halirutan would it be possible to overload that sendImage method to allow adding other parts to the MultipartEntity, like an API key?
if @yode is okay with having the image be uploaded to an anonymous account, then I would just use that method as is - but how do you pass image data as a byte[] through JLink?
8:36 PM
@JasonB Certainly.
It would be a bit hacky if you don't want to touch the Mathematica-Uploader Code at all, but basically it is: take the java code, change what you like and compile it into a jar. The jar replaces the one that comes with the SE-Tools.
@JasonB This is pretty simple as well:
data = ExportString[img, "PNG"];
Can I call that API to upload image but not by JAVA?@halirutan
@yode You mean like in your example? You want to upload an image directly to imgur from Mathematica, yes?
@yode Give me some minutes. I'm not working that often with http-request. Let me try something.
8:52 PM
The v11 have some improvement for http-request.It's seen that it is rarely used by everyone in SE.
@Mr.Wizard I didn't think you were complaining about the lack of votes, per se. I thought you were just looking for advice on how to improve your writing, an admirable goal, and conflating low votes with lack of attention. But, looking at your overall activity level on this site, I personally miss about half (if not more) which is disconcerting. But, then again, you have 10 times the answers I do. :)
9:06 PM
@yode I don't know. I'm getting an "Unauthorized" response, although I'm logging in with my imgur credentials.
Thanks all the same,my English is very poor so that I confuse its instruction still.Maybe I miss something important.@halirutan
@yode Do you have a client_id for imgur? Because I don't and I'm sure you need one.
Yes,I have
@yode You could look at the java code in this post and translate it directly into Mathematica code.
A: Imgur API uploading

Simegotry this out: public static String getImgurContent(String clientID) throws Exception { URL url; url = new URL("https://api.imgur.com/3/image"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); String data = URLEncoder.encode("image", "UTF-8") + "=" ...

Client Name:mmascript
Client ID:93d5e807261cc90
it's not a secret for me
9:39 PM
@yode I think I got it.
@LeonidShifrin maybe you should not question your M-abilities, but M's abilities ( for writing reusable code, for example ).
@yode, here we go:
$file = Export["tmp/img.png", Plot[Sin[x], {x, 0, 2 Pi}], "PNG"];
$req = HTTPRequest[URL["https://api.imgur.com/3/image"],
  <|Method -> "Post",
   "Headers" -> {
     "Authorization" -> "Client-ID 93d5e807261cc90",
     "Accept" -> "application/json"
   "Body" -> {"image" -> File[$file], "type" -> "file"}

And then you can inspect the HTTPResponse with
and you find the url and info of the uploaded image.
9:58 PM
@RolfMertig Well, may be. But given that M is what it is, this view can only be constructive if one is looking for reasons to switch from M to something else, while I will likely keep working with it for at least some time.
@LeonidShifrin We haven't talked in such a long time. Since you are here, maybe I can ask you a question.
@halirutan Long time indeed!
@halirutan Sure, please go ahead
Since a few weeks, I think from time to time how bad creating dynamic GUIs in Mathematica is from the viewpoint of separating data, model and controller. I was briefly looking through the web if there were any attempts to not build one big chunk of GUI/data/function mixture.
I found draw on the Wolfram GitHub page and the code there is, well... let's say very dense.
@LeonidShifrin Did you ever made a real attempt to build a GUI where the View, the Controller and the Model is separated?
(And the reason I asked this is because I had to work with JavaFX and it's SceneBuilder and when you see this, you really start to reconsider the options you have with Mathematica. It is beautiful and it is separated)
@halirutan I had in mind to follow the ideas from e.g. Angular and create something similar for Mathematica (perhaps not as comprehensive though). I did a few simple experiments which show that this is certainly possible. But I never had enough time to move further with these ideas.
I didn't work with JavaFX, alas, but I did work with angular.js, with the same feeling as you.
@LeonidShifrin So you are not aware of any online resources where someone might have attempted something like this for Mathematica?
10:10 PM
@halirutan Unfortunately, no.
But I am interested in that too.
And I do have a few ideas about this.
@LeonidShifrin I have a small project currently and there, I would need exactly this: It's about data visualization and what I need are different views for the same data. I started to write something but I really had hoped for someone who already made the mistakes I'm surely going to make now.
@halirutan We could discuss this offline (by email or otherwise), if you want. If I manage to help in some way, I will be happy. I am interested in this topic, too.
During recent months the lack of time was the biggest obstacle for me for any of the things I wanted to try.
Including this direction
@LeonidShifrin I guess I need a few more days to try something out and after that, I'm glad to discuss this. It's pretty general what I have in mind (can't discuss it here) and I'm sure you'll have ideas and you'll be interested.
@halirutan Sounds great. Looking forward to our discussion then!
@LeonidShifrin Another important thing:
I'm sure you saw the PrintDefinitions function in the GeneralUtilities package. This function re-formats code on its way and I read through some of the code.
10:22 PM
Yep, I am frequently using it myself (actually, used it a lot today)
Do you have from your IDE a function available that can re-format code? I'm pretty sure this would be an awesome idea for the SE-Uploader when people could select code cells and get a reformatted version in the clipboard that they can insert directly here.
I am currently sometimes using my code formatter for that, but it's not yet been integrated into the IDE. But I do have a version that works similarly to what you describe, posted that here
I think this can be modified to work as you describe
B.t.w., PrintDefinitions uses a different formatting algorithm, which might at the moment be superior to what I use for my code formatter - although I think I can improve my version to match it in quality
@LeonidShifrin I am sure I saw this post before. That is great and I can look through your code.
Also, PrintDefinitions actually allows you to patch the function you are viewing, since it parses correctly the contexts etc. Plus, you can navigate to other functions
I was thinking about combining ideas from my formatter and PrintDefinitions, although PrintDefinitions is actually already pretty good (it was written by Taliesin Beynon)
@LeonidShifrin We won't need this for pure copy&paste to SE.
10:27 PM
Sure. We won't.
@LeonidShifrin I was watching some of Taliesins YouTube videos to finally see who this guy is.
In fact, using this in the SE Uploader would give me the incentive to fix cases where the formatter doesn't yet do a good job
So, now you know
I guess
He did a number of important things, including Dataset, GeneralUtilities, TypeSystem and recently NeuralNetworks, plus a number of internal tools.
@LeonidShifrin Yes. You told me about him once.
That's why I was curious.
He was also partly responsible for the top-level design os Association, as well as design of operator forms in the language, among other things
@halirutan @LeonidShifrin I suffered in serveral projects during creating and maintaining somewhat more elaborated user interfaces and I would be also interested in a better MVC pattern for M. I am sure @Kuba is also interested, in fact he tried to generate (sophisticated multi-M-file) templating in IntelliJ, which probably should be done in M by means of TemplateObject and friends.
10:38 PM
@RolfMertig We already discussed this several times with @Kuba, and he indeed seems to be interested. But at least on my side, this didn't go further, mostly due to a lack of time.
That is the problem I have with WL these days: anything interesting takes a lot of time. It should be easier to extend the language and improve (software design) tools.
@RolfMertig Actually, it may not take that much time. My personal problem is, all the recent months I pretty much didn't have any at all, and when I did, I was too exhausted to use it for these things.
Maybe the WolframCloud crowd could get crazy and integrate something like codecanvas. Actually I think the standard notebook should just incorporate JavaScript anyway as a first citizen. Like all kind of MKL and other low-level (opensource and other) libraries are included into the Kernel, there should be better and more modern and responsive frameworks like D3.js "linkable" to the FrontEnd. Soon. Not in two years or so.
we should all visit you and have a M-Hackathlon...
@RolfMertig codecanvas looks like SceneBuilder from JavaFX. Drag and drop your stuff together and get a nice and clean XML file representing your GUI.
@RolfMertig That wouldn't be bad at all, I agree.

« first day (1850 days earlier)      last day (2651 days later) »