Meaning of graphical question-mark on reference hover in DrRacket? - racket

In the DrRacket GUI, hovering the mouse over a symbol often produces a graphical line between the symbol and other uses of the symbol in the file or a line from the symbol to an import origin for that symbol. Sometimes (but not always), the graphical line is accompanied by a graphical question mark (not a text question mark) as in the illustration below (look very carefully at the bottom of the line; the question mark is in dark purple on a black background, so it's quite hard to see, but it /is/ there). What is the meaning of that question mark?

DrRacket draws a blue arrow (no question mark) between a binding (definition, local binding, import, etc) and a reference to that binding.
It draws a purple arrow with a question mark between a binding and a possible reference within a syntax template. The question mark is a reminder that
that occurrence of the identifier might not be used as a reference
even if it is, it might refer to another binding
Here's a silly example:
#lang racket
(define-syntax-rule (define-undivider fname divisor)
(define (fname quotient remainder)
(println (list 'quotient quotient 'remainder remainder))
(+ (* divisor quotient) remainder)))
(define-undivider f 10)
(f 2 5) ;;=> 25
Some of the uses of quotient and remainder aren't references at all, because they occur inside of a quote expression. Others are references, but they refer to the function's arguments rather than the Racket functions. DrRacket can't tell that just by looking at the macro definition (and it's harder than you might think), so it marks the apparent binding relationship as a "maybe".

Related

How to create a Matlab symbol composition ∆t?

I'd like to create a single symbol which is contains a delta "∆" and a t.
For visualisation purposes i use Matlab Live Script.
Combining several latin letters is easy done by:
sym('dt')
But these either result in an exception or don't do a conversion:
sym('Delta t')
sym('Deltat')
The workaround to multiply two symbols does not work in all cases:
sym('Delta')*sym('t')
(sym('Delta')*sym('t'))^2
However, if i square the symbol, i'd like to have this behavior:
sym('dt')^2
But it should contain the delta symbol:
Is this what you want?
title('\Deltat')
If you want, you can also do
title('\Deltat^{2}')
The answer is no, you cant use non-ASCII for variables in MATLAB. This means no \Delta, no \epsilon, or any other non-standard chars.
You can generate the LaTeX representation of the results, and then print them either in text in MATLAB or in your favourite LaTeX editor with the function latex

Is there already any functions operates on latex equations mathematically in Emacs?

I have been thinking on editing latex equations mathematically in emacs:
Select current math term, shift it left and right, even across a "=" and changing signs. Terms are defined by "+" and "-" and other defined delimeters.
e.g. \alpha \bm{x} - 3\bm{y} = 10t, place cursor on "3" and call a function, the -3\bm{y} is selected. Call another function can change the equation to -3\bm{y}+\alpha\bm{x}=10t or \alpha \bm{x}=10t+3\bm{y}
Put coefficients into brackets, and even collect coefficients out.
e.g. With a function call can change 2(x+y) to (2x+2y).
Select current macro under cursor, copy the euqation from previous "=" or from a previous label.
The list goes on....
I have been using AUCTeX, CDLaTeX and RefTeX but up till now I do not know any functions already exists that can reach the effects above. So I want to ask if anyone knows an existing package in emacs can do these? If not, I am planning to elisp them myself

Reference to footnotes which outside of the current narrowed part buffer

During working within a narrowed part of a buffer by issuing C-x n s,
reference to footnotes, it will prompt
Definition is outside narrowed part of buffer [2 times]
The a sequence of operations should be operated:
- M-x widen - back to the original,
- View the footnote
- Back to the focus
- C-x n s return to narrowed part
Is it possible to reference to footnotes outside of the narrowed part?
I tried clone-indirect-buffer as
1) C-x n s narrow
2) clone-indirect-buffer and widen
3) back to the original narrowed
This solution does not work
and solution 2
1) clone-indirect-buffer
2) C-x n s narrow the original buffer
3) reference footnote in the original buffer,
still get the same error.

Primitives and built-in functions in Racket

Are primitives and built-in functions the same thing in Racket?
If no, what's the difference between them?
The short answer is no!
A primitive function are those which aren't implemented in its own runtime but inherently implemented by the runtime. eg. cons is implemented in C and the racket VM comes with the code that implements it. list* too, but it didn't really need to be a primitive. Some primitives are so just to speed things up.
Built in functions just means they come with the language. These are all primitives and all the standard library that is implemented in the language itself and is shipped with the implementation. An example is make-list. If you rigth click in the IDE and choose "Open defining file" you'll see it's implementation in racket:
(define (make-list n x)
(unless (exact-nonnegative-integer? n)
(raise-argument-error 'make-list "exact-nonnegative-integer?" n))
(let loop ([n n] [r '()])
(if (zero? n) r (loop (sub1 n) (cons x r)))))
An example of function that are neither primitive nor built in would be many of the packages in pkgs.racket-lang.org.

Plotting data sequentially from emacs using Common Lisp and Gnuplot

Assume that I have some array of data (a vector to be specific).
Can I plot it element by element sequentially using Gnuplot such that it seems as if it is a real life signal that is being traced through a monitor?
I know that I can write the whole data into a text file using Common Lisp, then using gnuplot I can plot it in a batch format. What I require is that I want to put a point on my plot as data comes sequentially.
Data will probably be generated inside a loop, thus you may consider x-axis as the integer valued discrete-time axis. So in the loop if the first element of the array is generated as 5, I would like to put a point on my plot to (0,5). Then if the second element is generated as 3, I would like to put another point on my plot to (1,7) (preserving the old data point). So as I iterate through the loop, I plot the data sequentially.
I am using emacs and Common Lisp for my purposes and I want to plot this data staying within these tools. If there are any other options other than Gnuplot, I would like to hear them.
If this is not easily possible, it would be cool, if I can run a Gnuplot command file by some Common Lisp command.
edit:
Following advices people gave under this thread, I wrote a code using cgn which uses ltk.
Right now I open two x11 windows at pre-specified positions on my screen and I enter the loop. In loop each time I open a stream and write the data (sine and cosine waves of 0.25 Hz sampled at 20 Hz) to the text file trial.txt with the :if-exists :append option and close the stream. Then at each iteration I plot the whole data using the gnuplot through the format-gnuplot command. This code gives me two windows of pre-specified x and y ranges and then one can watch the evolutions of aforementioned sine and cosine waves in the windows.
As I have stated before I don't have strong programming background (I am an electrical engineer who somehow ended using common lisp) and I am pretty sure that my code is non-optimal and unelegant. If you guys have some further advices, corrections etc. I would really like to hear them. The code is here:
(setf filename "trial.txt")
(setf path (make-pathname :name filename))
(setf str (open path :direction :output :if-exists :supersede :if-does-not-exist :create))
(format str "~,4F ~,4F" -1 -1)
(close str)
;start gnuplot process
(start-gnuplot "/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot")
;set 2 x11 windows with the following properties
(format-gnuplot "cd ~S" "Users/yberol/Desktop/lispbox/code")
(format-gnuplot "set terminal x11 0 position 0,0")
(format-gnuplot "set xrange [0:10]")
(format-gnuplot "set yrange [-1:1]")
(format-gnuplot "unset key")
(format-gnuplot "set grid")
(format-gnuplot "plot ~S using 1" filename)
(format-gnuplot "set terminal x11 1 position 800,0")
(format-gnuplot "plot ~S using 2" filename)
;write data into text
(loop :for i :from 0 :to 10 :by (/ 1 20) :do
(setf str (open path :direction :output :if-exists :append :if-does-not-exist :create))
(format str "~,4F ~,4F ~,4F ~%" i (sin (* 2 pi (/ 5 20) i)) (cos (* 2 pi (/ 5 20) i)))
(close str)
(format-gnuplot "set terminal x11 0")
(format-gnuplot "plot ~S using 1:2 with lines" filename)
(format-gnuplot "set terminal x11 1")
(format-gnuplot "plot ~S using 1:3 with lines" filename)
(sleep 0.1))
(close-gnuplot)
Thank you very much.
cgn is a working Common Lisp solution for interfacing with gnuplot, which uses LTK
You could create process to gnuplot and send data to it's stdin along with plotting commands. I'm not sure how to manage such process in Common Lisp but you definitely can do this in Emacs:
(setf *gnuplot-proc* (start-process "gnuplot" "*gnuplot-proc*" "gnuplot"))
;;; initiate plotting of data from stdin
(process-send-string *gnuplot-proc*
"plot \"-\" with lines\n")
;; send your data
(process-send-string *gnuplot-proc*
"5 -1\n4 -3.5\n3 9.5\n")
;; end of data, after this gnuplot would pop up interactive window
(process-send-string *gnuplot-proc* "e\n")
With such asynchronous process it's easy to write something to make it interactively update plot as new data comes along.
You might have a look at the orgplot mode, which ties gnuplot into emacs org tables.
http://orgmode.org/worg/org-tutorials/org-plot.html
You could use eazy-gnuplot, I do. See it here: eazy-gnuplot examples. The github repo is here: github repo. I don't have more time to provide an example here, sorry.
I am not experienced with Gnuplot, and a quick search didn't turn up too much information. But perhaps i can propose an approach. Say you chunk your input, for example '(1 2 3 4 5) would be '((1) (1 2) (1 2 3) (1 2 3 4) (1 2 3 4 5)), you can then generate a plot for each, and use a graphics library like lispbuilder-sdl to display it in a window with a time delay. SDL has a timer and it can display images just fine.