Getting the date format for the current locale - date

When I first stumbled across the constant defaultTimeLocale in System.Locale, I supposed it should contain the default TimeLocale for the current locale.
After some trying around, I realized that it always contains the same constants and looking at the source code of System.Locale quickly revealed that it's in fact only a constant. (Later I realized that the type also tells me that. Since defaultTimeLocale isn't an IO value and doesn't take any arguments it has to be constant.)
What is the way in Haskell to get the current TimeLocale with respect to the current locale?

System.CurrentLocale.currentLocale :: IO TimeLocale
from package current-locale
looks suitable.
I did not test it. Looking at its source code, it should work. I actually do not like it very much since underneath it spawns four date subprocesses (!), which is rather overkill for this simple task, IMHO.
Probably it can be rewritten to use some C or POSIX function instead.

Related

VSCode peek variable declaration for unsupported languages

Is it possible in VSCode to peek the declaration (or first mention) of a certain variable in unsupported languages?
I work a lot with Matlab, and in long scripts it would be helpful if I could have a little peek window (as in e.g. C, Python) to see the first definition of the variable. Of course this variable could have been changed in the script (and without proper symbols there is probably not really a way to detect this), but let's assume that it isn't.
To illustrate what I mean with a Python example:

Uniform list pretty-printer

It is known that default printer can be confusing wrt lists because of no output for empty lists and 3 different notations being mixed (, vs (x;y;z) vs 1 2 3) and not obvious indentation/columnization (which is apparently optimized for table data). I am currently using -3! but it is still not ideal.
Is there a ready-made pretty-printer that has consistent uniform output format (basically what I am used to in any other language where list is not special)?
I've started using .j.j for string outputs in error messages more recently in preference to -3!. Mainly I think it is easier to parse in a text log, but also doesn't truncate in the same way.
It still transforms atoms and lists differently so it might not exactly meet your needs, if you really want that you could compose it with the old "ensure this is a list" trick:
myPrinter:('[.j.j;(),])
You might need to supply some examples to better explain your issues and your use-case for pretty-printing.
In general -3! is the most clear visual representation of the data. It is the stringified equivalent to another popular display method which is 0N!.
The parse function is useful for understanding how the interpreter reads/executes commands but I don't think that will be useful in your case

Handle date and time in ocaml

Is there a way to handle date and time, some sort of module, in ocaml ? Vanilla ocaml i mean, so no OPAM, or this kind of things ?
It seems like there is nothing about it on the internet, i would have expected more docs for the OCaml langage, it's so frustrating...
I need it to do operations on date and time, transform date and times into seconds from epoch, and reverse it, ect...
If there is no way i will do my own functions, but if there is something already done in OCaml for that that would be way better !
OCaml Unix library provides the interface to standard POSIX date/time functions such as time, mktime, gmtime, and localtime. They should be sufficient for your task. See the standard OCaml documentation for futher information.
Also, long time ago I wrote a small library that depends purely on the Unix module, and implements a few useful time transformations. I never published it, but feel free to grab the code, or use it as a set of examples.
And of course, there are plenty of libraries available in OPAM, or via a package manager of your operating system. It is always better, to reuse existing code, rather then duplicate it.

At which lines in my MATLAB code a variable is accessed?

I am defining a variable in the beginning of my source code in MATLAB. Now I would like to know at which lines this variable effects something. In other words, I would like to see all lines in which that variable is read out. This wish does not only include all accesses in the current function, but also possible accesses in sub-functions that use this variable as an input argument. In this way, I can see in a quick way where my change of this variable takes any influence.
Is there any possibility to do so in MATLAB? A graphical marking of the corresponding lines would be nice but a command line output might be even more practical.
You may always use "Find Files" to search for a certain keyword or expression. In my R2012a/Windows version is in Edit > Find Files..., with the keyboard shortcut [CTRL] + [SHIFT] + [F].
The result will be a list of lines where the searched string is found, in all the files found in the specified folder. Please check out the options in the search dialog for more details and flexibility.
Later edit: thanks to #zinjaai, I noticed that #tc88 required that this tool should track the effect of the name of the variable inside the functions/subfunctions. I think this is:
very difficult to achieve. The problem of running trough all the possible values and branching on every possible conditional expression is... well is hard. I think is halting-problem-hard.
in 90% of the case the assumption that the output of a function is influenced by the input is true. But the input and the output are part of the same statement (assigning the result of a function) so looking for where the variable is used as argument should suffice to identify what output variables are affected..
There are perverse cases where functions will alter arguments that are handle-type (because the argument is not copied, but referenced). This side-effect will break the assumption 2, and is one of the main reasons why 1. Outlining the cases when these side effects take place is again, hard, and is better to assume that all of them are modified.
Some other cases are inherently undecidable, because they don't depend on the computer states, but on the state of the "outside world". Example: suppose one calls uigetfile. The function returns a char type when the user selects a file, and a double type for the case when the user chooses not to select a file. Obviously the two cases will be treated differently. How could you know which variables are created/modified before the user deciding?
In conclusion: I think that human intuition, plus the MATLAB Debugger (for run time), and the Find Files (for quick search where a variable is used) and depfun (for quick identification of function dependence) is way cheaper. But I would like to be wrong. :-)

Current memory usage in Lisp

I need to find out, from within a Common Lisp program, how much memory is currently being used.
I'm given to understand there is no portable method (the standard function room prints the information to standard output in text form instead of returning it as a value), but sb-kernel:dynamic-usage works in SBCL.
What are the equivalents in other Common Lisp implementations? Or is there another way to solve this problem I should be looking at?
It may not help you much, but anyway:
You can capture the output of (room) and parse it.
(with-output-to-string (*standard-output*)
(room))
Above returns a string with the output of ROOM.
Additionally it may help to request the memory size of the process via an external call to a standard unix command (if you are on Unix).
For things which virtually every implementation supports, but not in the same way (because it's not in CL), one common approach is to make a library called trivial-whatever.
If you started a package like trivial-memory, and supplied the first implementation, I'm sure we could get everybody to contribute the function for their own favorite Lisp compiler in short order. :-)