Why can't I write a byte to the current-output-port in the REPL? - scheme

Why does (write-u8 49 current-output-port) fail with an error when I evaluate it in an REPL?
chibi-scheme 0.10.0:
> (write-u8 49 current-output-port)
ERROR in "write-u8": invalid type, expected Output-Port: #<opcode "current-output-port">
Guile 3.0.8:
scheme#(guile-user)> (import (scheme base))
scheme#(guile-user)> (write-u8 49 current-output-port)
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure put-u8: Wrong type argument in position 1 (expecting open output port): #<<parameter> 7f38972eb9c0 proc: #<procedure 7f38972f4200 at ice-9/boot-9.scm:1361:3 () | (x)>>
MIT Scheme 11.2:
1 ]=> (write-u8 49 current-output-port)
;The object #[compiled-closure 12 ("dynamic" #xd) #x17c #x27f522c ...], passed as an argument to #[compiled-procedure 13 ("binary-port" #x3) #x1c #x291d984], is not the correct type

current-output-port is a procedure. You have to call it and use its return value as an argument to write-u8.
(write-u8 49 (current-output-port))

Related

Missing ',' in line when Biopython reads a nexus tree

I want to edit a tree that I got from BEAST2 treeannotator in nexus-format.
Usually I use the module Phylo from Biopython for such work but Phylo.read(r"filename.tree", "nexus") gave me the next exception:
---------------------------------------------------------------------------
NexusError Traceback (most recent call last)
Input In [29], in <cell line: 1>()
----> 1 Phylo.read(r"filename.tree", "nexus")
File ~\miniconda3\lib\site-packages\Bio\Phylo\_io.py:60, in read(file, format, **kwargs)
58 try:
59 tree_gen = parse(file, format, **kwargs)
---> 60 tree = next(tree_gen)
61 except StopIteration:
62 raise ValueError("There are no trees in this file.") from None
File ~\miniconda3\lib\site-packages\Bio\Phylo\_io.py:49, in parse(file, format, **kwargs)
34 """Parse a file iteratively, and yield each of the trees it contains.
35
36 If a file only contains one tree, this still returns an iterable object that
(...)
46
47 """
48 with File.as_handle(file) as fp:
---> 49 yield from getattr(supported_formats[format], "parse")(fp, **kwargs)
File ~\miniconda3\lib\site-packages\Bio\Phylo\NexusIO.py:40, in parse(handle)
32 def parse(handle):
33 """Parse the trees in a Nexus file.
34
35 Uses the old Nexus.Trees parser to extract the trees, converts them back to
(...)
38 eventually change Nexus to use the new NewickIO parser directly.)
39 """
---> 40 nex = Nexus.Nexus(handle)
42 # NB: Once Nexus.Trees is modified to use Tree.Newick objects, do this:
43 # return iter(nex.trees)
44 # Until then, convert the Nexus.Trees.Tree object hierarchy:
45 def node2clade(nxtree, node):
File ~\miniconda3\lib\site-packages\Bio\Nexus\Nexus.py:668, in Nexus.__init__(self, input)
665 self.options["gapmode"] = "missing"
667 if input:
--> 668 self.read(input)
669 else:
670 self.read(DEFAULTNEXUS)
File ~\miniconda3\lib\site-packages\Bio\Nexus\Nexus.py:718, in Nexus.read(self, input)
716 break
717 if title in KNOWN_NEXUS_BLOCKS:
--> 718 self._parse_nexus_block(title, contents)
719 else:
720 self._unknown_nexus_block(title, contents)
File ~\miniconda3\lib\site-packages\Bio\Nexus\Nexus.py:759, in Nexus._parse_nexus_block(self, title, contents)
757 for line in block.commandlines:
758 try:
--> 759 getattr(self, "_" + line.command)(line.options)
760 except AttributeError:
761 raise NexusError("Unknown command: %s " % line.command) from None
File ~\miniconda3\lib\site-packages\Bio\Nexus\Nexus.py:1144, in Nexus._translate(self, options)
1142 break
1143 elif c != ",":
-> 1144 raise NexusError("Missing ',' in line %s." % options)
1145 except NexusError:
1146 raise
NexusError: Missing ',' in line 1 AB298157.1_2015_-7.9133750332192605_114.8086828279248, 2 AB298158.1_2007_-8.41698974207…
Using Nexus.read(Nexus(), input=r"filename.tree") gave the same result. Please could anyone help with this? I cannot understand the reason of this error because nexus file looks correct.
The reason is that Biopython cannot read nexus trees with links, constituent from translations & a newick tree. So it is required previously to convert this to the form with full names into the tree (as hereinbelow).
Begin
tree TREE1 = (((your,tree),(in,(the, newick))),format);
End;
P.S. It is allowed in the newick format to surround the label with quotes, & some programmes or scripts add them to those names that have ambiguous characters. But it can lead to exceptions during the following phylogenetic analysis, for instance, in BEAST. I wish you would be careful with this.

What's the difference between define and defmacro-public

I try to decipher libctl.
In base/io-vars.scm, defmacro-public appears.
58(defmacro-public define-input-var
59 (name init-val var-type-name . var-constraints)
60 `(begin
61 (define-param ,name ,init-val)
62 (input-var! (lambda () ,name) (quote ,name)
63 ,var-type-name ,#var-constraints)))
I can't find the definition of defmacro-public.
What's the definition of defmacro-public and what's the difference between defmacro-public and define ?

Pig Scripting - Cast STRING to INT

Beginner in Pig, Need help
For all NON - AlphaNumeric, Cast the STRING TO INT
- To be handled without passing each field name separately.
Sample data -
00013425731998101620140402300032736901 00000000AAA001200X111685V00000000
00283335542006120920131010300030003105 00000000AAA001200X117407 00000000
00000000331998101620140402300033128107 00000000AAA001200X111685 00000000
00003902331999090620140402300032545208 00000000AAA001200X111685 00000000
Its a fixedwidth file, mapping details as follow -
orderNumber 1 9
origin 10 10
Startdate 11 18
ModDate 19 26
Identifier 27 36
Code 37 38
CodeType 39 40
Number 41 48
Num 49 114
Either use substr to extract the parts and then cast them or use a regexp. For example for the first two fields:
input = load ... as (line:chararray);
a = foreach input generate SUBSTRING(line, 0, 9) as orderNumber:long, SUBSTRING(line, 9, 10) as origin:chararray;
This way you should be able to convert each part of the input line into the desired components.
Alternatively you could write a UDF that takes a string as input and does the splitting and returns a bag or tuple.

What is the meaning of numbers in inline assemble

Do anyone know what the following code does?
I'm not sure what the 1, 2, 3 is refered and how they are used here. :-(
95 asm volatile("2: wrmsr ; xor %[err],%[err]\n"
96 "1:\n\t"
97 ".section .fixup,\"ax\"\n\t"
98 "3: mov %[fault],%[err] ; jmp 1b\n\t"
99 ".previous\n\t"
100 _ASM_EXTABLE(2b, 3b)
101 : [err] "=a" (err)
102 : "c" (msr), "" (low), "d" (high),
103 [fault] "i" (-EIO)
104 : "memory");
105 return err;​
The code is from Linux: http://lxr.free-electrons.com/source/arch/x86/include/asm/msr.h#L91
I really appreciate it ​if anyone could give me some key word to google it.
Thank you very much in advance!
Those are local labels (numbers followed by a colon).
When they are later referenced, the b (as in jmp 1b) means to refer to the nearest local label of that number going backwards. An f would look for a matching local label later (forwards) in the code.
That code declares an exception table, when an exception occurs executing the wrmsr instruction, the fault handler (usually in arch/<your_CPU_arch>/mm/fault.c) searches the exception table for the corresponding entry, and jumps there.
As you can see, the entry for that exception moves EIO into err, and jumps back to the instruction following the xor (which would clear err in case there was no error).

What are the numbers on the end of lines in a stacktrace

What do the the numbers after the "+" at the end of the lines in a stack trace represent?
Function Source
ntdll!KiFastSystemCallRet
ntdll!ZwRemoveIoCompletion+c
kernel32!GetQueuedCompletionStatus+29
w3tp!THREAD_POOL_DATA::ThreadPoolThread+33
w3tp!THREAD_POOL_DATA::ThreadPoolThread+24
w3tp!THREAD_MANAGER::ThreadManagerThread+39
kernel32!BaseThreadStart+34
here they are
+c
+29
+33
+24
+39 +34
They are offsets, in hexadecimal, from the start of the named subroutine. For example
kernel32!BaseThreadStart+34
is 52 (34 hex) bytes into the routine BaseThreadStart in the kernel32 module.
Offset inside the function. Eg. on frame 3 the return address is: the address of the kernel32!GetQueuedCompletionStatus symbol + 29 bytes.

Resources