Unbound variable 'trace' - terminal

I'm trying to use the guile function trace, but every time I do, I get a possible unbound variable.
scheme#(guile-user)> (define (fact1 n)
(if (zero? n) 1
(* n (fact1 (- n 1)))))
scheme#(guile-user)> (trace fact1)
;;; <stdin>:4:0: warning: possibly unbound variable `trace'
<unnamed port>:4:0: In procedure #<procedure 10e4080c0 at <current input>:4:0 ()>:
<unnamed port>:4:0: In procedure module-lookup: Unbound variable: trace
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme#(guile-user) [1]>
I was wondering if anyone knows why this is not working.

Use ,trace:
GNU Guile 2.0.12
Copyright (C) 1995-2016 Free Software Foundation, Inc.
Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.
Enter `,help' for help.
scheme#(guile-user)> (define (fact1 n)
... (if (zero? n) 1
... (* n (fact1 (- n 1)))))
scheme#(guile-user)> ,trace (fact1 5)
trace: | (#<procedure 110221480> #(#<directory (guile-user) 10f9fabd0> #f))
trace: | #(#<directory (guile-user) 10f9fabd0> fact1)
trace: (#<procedure 11022e1e0 at <current input>:2:0 ()>)
trace: (fact1 5)
trace: | (fact1 4)
trace: | | (fact1 3)
trace: | | | (fact1 2)
trace: | | | | (fact1 1)
trace: | | | | | (fact1 0)
trace: | | | | | 1
trace: | | | | 1
trace: | | | 2
trace: | | 6
trace: | 24
trace: 120

Related

bash looping and extracting of the fragment of txt file

I am dealing with the analysis of big number of dlg text files located within the workdir. Each file has a table (usually located in different positions of the log) in the following format:
File 1:
CLUSTERING HISTOGRAM
____________________
________________________________________________________________________________
| | | | |
Clus | Lowest | Run | Mean | Num | Histogram
-ter | Binding | | Binding | in |
Rank | Energy | | Energy | Clus| 5 10 15 20 25 30 35
_____|___________|_____|___________|_____|____:____|____:____|____:____|____:___
1 | -5.78 | 11 | -5.78 | 1 |#
2 | -5.53 | 13 | -5.53 | 1 |#
3 | -5.47 | 17 | -5.44 | 2 |##
4 | -5.43 | 20 | -5.43 | 1 |#
5 | -5.26 | 19 | -5.26 | 1 |#
6 | -5.24 | 3 | -5.24 | 1 |#
7 | -5.19 | 4 | -5.19 | 1 |#
8 | -5.14 | 16 | -5.14 | 1 |#
9 | -5.11 | 9 | -5.11 | 1 |#
10 | -5.07 | 1 | -5.07 | 1 |#
11 | -5.05 | 14 | -5.05 | 1 |#
12 | -4.99 | 12 | -4.99 | 1 |#
13 | -4.95 | 8 | -4.95 | 1 |#
14 | -4.93 | 2 | -4.93 | 1 |#
15 | -4.90 | 10 | -4.90 | 1 |#
16 | -4.83 | 15 | -4.83 | 1 |#
17 | -4.82 | 6 | -4.82 | 1 |#
18 | -4.43 | 5 | -4.43 | 1 |#
19 | -4.26 | 7 | -4.26 | 1 |#
_____|___________|_____|___________|_____|______________________________________
The aim is to loop over all the dlg files and take the single line from the table corresponding to wider cluster (with bigger number of slashes in Histogram column). In the above example from the table this is the third line.
3 | -5.47 | 17 | -5.44 | 2 |##
Then I need to add this line to the final_log.txt together with the name of the log file (that should be specified before the line). So in the end I should have something in following format (for 3 different log files):
"Name of the file 1": 3 | -5.47 | 17 | -5.44 | 2 |##
"Name_of_the_file_2": 1 | -5.99 | 13 | -5.98 | 16 |################
"Name_of_the_file_3": 2 | -4.78 | 19 | -4.44 | 3 |###
A possible model of my BASH workflow would be:
#!/bin/bash
do
file_name2=$(basename "$f")
file_name="${file_name2/.dlg}"
echo "Processing of $f..."
# take a name of the file and save it in the log
echo "$file_name" >> $PWD/final_results.log
# search of the beginning of the table inside of each file and save it after its name
cat $f |grep 'CLUSTERING HISTOGRAM' >> $PWD/final_results.log
# check whether it works
gedit $PWD/final_results.log
done
Here I need to substitute combination of echo and grep in order to take selected parts of the table.
You can use this one, expected to be fast enough. Extra lines in your files, besides the tables, are not expected to be a problem.
grep "#$" *.dlg | sort -rk11 | awk '!seen[$1]++'
grep fetches all the histogram lines which are then sorted in reverse order by last field, that means lines with most # on the top, and finally awk removes the duplicates. Note that when grep is parsing more than one file, it has -H by default to print the filenames at the beginning of the line, so if you test it for one file, use grep -H.
Result should be like this:
file1.dlg: 3 | -5.47 | 17 | -5.44 | 2 |##########
file2.dlg: 3 | -5.47 | 17 | -5.44 | 2 |####
file3.dlg: 3 | -5.47 | 17 | -5.44 | 2 |#######
Here is a modification to get the first appearence in case of many equal max lines in a file:
grep "#$" *.dlg | sort -k11 | tac | awk '!seen[$1]++'
We replaced the reversed parameter in sort, with the 'tac' command which is reversing the file stream, so now for any equal lines, initial order is preserved.
Second solution
Here using only awk:
awk -F"|" '/#$/ && $NF > max[FILENAME] {max[FILENAME]=$NF; row[FILENAME]=$0}
END {for (i in row) print i ":" row[i]}' *.dlg
Update: if you execute it from different directory and want to keep only the basename of every file, to remove the path prefix:
awk -F"|" '/#$/ && $NF > max[FILENAME] {max[FILENAME]=$NF; row[FILENAME]=$0}
END {for (i in row) {sub(".*/","",i); print i ":" row[i]}}'
Probably makes more sense as an Awk script.
This picks the first line with the widest histogram in the case of a tie within an input file.
#!/bin/bash
awk 'FNR == 1 { if(sel) print sel; sel = ""; max = 0 }
FNR < 9 { next }
length($10) > max { max = length($10); sel = FILENAME ":" $0 }
END { if (sel) print sel }' ./"$prot"/*.dlg
This assumes the histograms are always the tenth field; if your input format is even messier than the lump you show, maybe adapt to taste.
In some more detail, the first line triggers on the first line of each input file. If we have collected a previous line (meaning this is not the first input file), print that, and start over. Otherwise, initialize for the first input file. Set sel to nothing and max to zero.
The second line skips lines 1-8 which contain the header.
The third line checks if the current line's histogram is longer than max. If it is, update max to this histogram's length, and remember the current line in sel.
The last line is spillover for when we have processed all files. We never printed the sel from the last file, so print that too, if it's set.
If you mean to say we should find the lines between CLUSTERING HISTOGRAM and the end of the table, we should probably have more information about what the surrounding lines look like. Maybe something like this, though;
awk '/CLUSTERING HISTOGRAM/ { if (sel) print sel; looking = 1; sel = ""; max = 0 }
!looking { next }
looking > 1 && $1 != looking { looking = 0; nextfile }
$1 == looking && length($10) > max { max = length($10); sel = FILENAME ":" $0 }
END { if (sel) print sel }' ./"$prot"/*.dlg
This sets looking to 1 when we see CLUSTERING HISTOGRAM, then counts up to the first line where looking is no longer increasing.
I would suggest processing using awk:
for i in $FILES
do
echo -n \""$i\": "
awk 'BEGIN {
output="";
outputlength=0
}
/(^ *[0-9]+)/ { # process only lines that start with a number
if (length(substr($10, 2)) > outputlength) { # if line has more hashes, store it
output=$0;
outputlength=length(substr($10, 2))
}
}
END {
print output # output the resulting line
}' "$i"
done

how to exit Gallium debugger?

what's the command to exit the Gallium debugger for Julia? I tried all things like q, Q, exit(), exit, Ctrl-c.
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.5.0 (2016-09-19 18:14 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-apple-darwin13.4.0
julia> using Gallium
julia> include(Pkg.dir("Gallium/examples/testprograms/misc.jl"))
optional (generic function with 2 methods)
julia> Gallium.breakpoint(sinthesin,Tuple{Int64})
Locations (+: active, -: inactive, *: source):
+ sinthesin(x::Int64) at /Users/florian.oswald/.julia/v0.5/Gallium/examples/testprograms/misc.jl:2
julia> inaloop(2)
In /Users/florian.oswald/.julia/v0.5/Gallium/examples/testprograms/misc.jl:2
1 #noinline function sinthesin(x)
2 sin(sin(x))
3 end
4
About to run: Main.sin
1|debug > q
In /Users/florian.oswald/.julia/v0.5/Gallium/examples/testprograms/misc.jl:2
1 #noinline function sinthesin(x)
2 sin(sin(x))
3 end
4
About to run: Main.sin
1|debug >
UPDATE
there is a related issue on github. The main takeaway from this is to use #enter func(x,y) and step into a function directly. i find this works pretty well.
When working with REPL, you can use finish to exit the current function. To exit debugger, you may need to execute this command several times.
In Atom, the corresponding command is the Debug: Finish Function button.
You can find more commands here.
UPDATE:
A breakpoint pauses the program whenever a certain point in the program is reached. In your example, inaloop(2) will call sinthesin twice, so a single q or Ctrl+d is not enough to exit the debugger. I think this is the expected behavior, take a look at the following example:
julia> bp = Gallium.breakpoint(sinthesin,Tuple{Int64})
Locations (+: active, -: inactive, *: source):
+ sinthesin(x::Int64) at /Users/gnimuc/.julia/v0.5/Gallium/examples/testprograms/misc.jl:2
julia> inaloop(2)
In /Users/gnimuc/.julia/v0.5/Gallium/examples/testprograms/misc.jl:2
1 #noinline function sinthesin(x)
2 sin(sin(x))
3 end
4
About to run: Main.sin
1|debug > q
In /Users/gnimuc/.julia/v0.5/Gallium/examples/testprograms/misc.jl:2
1 #noinline function sinthesin(x)
2 sin(sin(x))
3 end
4
About to run: Main.sin
1|debug > q
julia>
julia> Gallium.disable(bp)
true
julia> #enter inaloop(2)
In /Users/gnimuc/.julia/v0.5/Gallium/examples/testprograms/misc.jl:6
5 #noinline function inaloop(y)
6 for i = 1:y
7 sinthesin(i)
8 end
About to run: (colon)(1,2)
1|debug > q
Adding to Gnimuc's answer you should also be able to exit the debugger with the q command.
From here:
const all_commands = ("q", "s", "si", "finish", "bt", "loc", "ind", "shadow",
"up", "down", "ns", "nc", "n", "se")

Writing conditions in Conjunctive Normal Form

Conjunctive Normal Form (CNF) is a standardized notation for propositional formulas that dictate that every formula should be written as a conjunction of disjunctions. Every boolean formula can be converted to CNF. So for example:
A | (B & C)
Has a representation in CNF like this:
(A | B) & (A | C)
Is it a best practice in programming to write conditionals in CNF?
No, this is not a good idea. Conjunctive normal form is primarily used in theoretical computer science. There are algorithms to solve formulas in CNF, and proofs about time complexity and NP-hardness.
From a pragmatic point of view, you should write code using Boolean operators that most "naturally" describe the logic. This means taking full advantage of nested expressions, operators like XOR, negation, and so on. As you exemplified, CNF often contradicts this goal of "naturalness" because the expression is longer and often repeats subexpressions.
As a theoretical side note, in the worst case, an unrestricted Boolean formula containing n operators can transform into a CNF formula whose length is exponential in n. So CNF can potentially blow up a formula by very large amount. A sequence of examples illustrating this behavior:
(A & B) | (C & D) ==
(A | C) & (A | D) & (B | C) & (B | D).
(A & B) | (C & D) | (E & F) ==
(A | C | E) & (A | C | F) & (A | D | E) & (A | D | F) & (B | C | E) & (B | C | F) & (B | D | E) & (B | D | F).
(A & B) | (C & D) | (E & F) | (G & H) ==
(A | C | E | G) & (A | C | E | H) & (A | C | F | G) & (A | C | F | H) & (A | D | E | G) & (A | D | E | H) & (A | D | F | G) & (A | D | F | H) & (B | C | E | G) & (B | C | E | H) & (B | C | F | G) & (B | C | F | H) & (B | D | E | G) & (B | D | E | H) & (B | D | F | G) & (B | D | F | H).

37 - No locks available' from fcntl while using Multi Instance MQ

I am trying to set up Multi Instacnce MQ. I am using MQ v7.5. I am following the below steps:
Installed MQ in Server A and Server B
Configured NFS in Server A(acting as server) and in Server B (acting as client) in a folder MQ.
Created a queue manager in server A using the below command crtmqm -ld /MQ/logs -md /MQ/qmrgs -q QM1
Got the queue manager information using dspmqinf -o command QM1
In Server B used addmqinf <queue info from server A>
Start the queue manager in Server A using strmqm -x QM1 and its started successfully.
Start the queue manager in Server B using strmqm -x QM1 and its failed to start.
I got the below FDC:
+-----------------------------------------------------------------------------+
| |
| WebSphere MQ First Failure Symptom Report |
| ========================================= |
| |
| Date/Time :- Mon November 10 2014 15:23:29 IST |
| UTC Time :- 1415613209.614999 |
| UTC Time Offset :- 330 (IST) |
| Host Name :- InBlrBnc60 |
| Operating System :- Linux 2.6.32-71.el6.x86_64 |
| PIDS :- 5724H7230 |
| LVLS :- 7.5.0.0 |
| Product Long Name :- WebSphere MQ for Linux (x86-64 platform) |
| Vendor :- IBM |
| Installation Path :- /opt/mqm |
| Installation Name :- Installation1 (1) |
| Probe Id :- XY509007 |
| Application Name :- MQM |
| Component :- xcsOpenFileLock |
| SCCS Info :- /build/p000_P/src/lib/cs/unix/amqxnflx.c, |
| Line Number :- 428 |
| Build Date :- Jun 4 2012 |
| Build Level :- p000-L120604 |
| Build Type :- IKAP - (Production) |
| Effective UserID :- 525 (mqm) |
| Real UserID :- 525 (mqm) |
| Program Name :- crtmqm |
| Addressing mode :- 64-bit |
| LANG :- en_US.UTF-8 |
| Process :- 16729 |
| Process(Thread) :- 16729 |
| Thread :- 1 |
| ThreadingModel :- PosixThreads |
| QueueManager :- MQ1 |
| UserApp :- FALSE |
| ConnId(2) QM :- 2 |
| Last HQC :- 2.0.0-5133648 |
| Last HSHMEMB :- 2.1.1-22456 |
| Major Errorcode :- xecF_E_UNEXPECTED_SYSTEM_RC |
| Minor Errorcode :- OK |
| Probe Type :- MSGAMQ6119 |
| Probe Severity :- 2 |
| Probe Description :- AMQ6119: An internal WebSphere MQ error has occurred |
| ('37 - No locks available' from fcntl.) |
| FDCSequenceNumber :- 0 |
| Arith1 :- 37 (0x25) |
| **Comment1 :- '37 - No locks available' from fcntl.**
I tried browsing about 37 - No locks available' from fcntl, but not able to get why this error is coming. I have verified my system config with su mqm -c /opt/mqm/bin/mqconfig and it satisfies the MQ recommended value. I have also verified my NFS set up is working fine.

Emacs, toggle a specific window

I have a buffer that I want to "toggle" opening in a window in emacs on a keypress.
For example:
________________ ________________ ________________
| | | | | | |
| | | | | | |
| | | | | | |
| W | -> | S | W | -> | W |
| | <f3> | | | <f3> | |
| | | | | | |
---------------- ---------------- ----------------
Where S in the left hand side window is a specific buffer.
The problem arises that this should happen regardless of what the window structure of W is. If W has a couple of different windows in it, pressing <F3> should still create a new window at the edge of the screen, and put the specific buffer in it, and then it should take it away.
I'm not really sure how to do this is emacs however.
Try this as the starting point, it needs package popwin.
(require 'popwin)
(popwin-mode 1)
(generate-new-buffer "special-buffer")
(setq eab/special-buffer-displaedp nil)
(setq eab/special-buffer "special-buffer")
(add-to-list 'popwin:special-display-config
`(,eab/special-buffer :width 20 :position left :stick t))
(defun eab/special-buffer-toggle ()
(interactive)
(if eab/special-buffer-displaedp
(progn
(popwin:close-popup-window)
(setq eab/special-buffer-displaedp nil))
(progn
(ignore-errors (popwin:display-buffer eab/special-buffer))
(setq eab/special-buffer-displaedp 't))))
(global-set-key (kbd "<f3>") 'eab/special-buffer-toggle)

Resources