我發現有新的版本,所以更新了我自己的 openSUSE RPM spec。
casstcl 需要 cassandra cpp driver,我也有寫一個 openSUSE RPM spec,在安裝 casstcl 前需要先安裝 cassandra cpp driver。
2019-08-19
2019-08-05
MAWT (Movie Automation With Tcl) 0.2.0
MAWT - Movie Automation With Tcl 已經在 2019/06/20 釋出了 0.2.0。
0.2.0 更新的資訊:
Improved video generation functionality.
所以我也更新了我自己的 openSUSE 套件。
0.2.0 更新的資訊:
Improved video generation functionality.
所以我也更新了我自己的 openSUSE 套件。
2019-06-08
Tclsh and Here document
Here document
之前我只有在 bash 使用過,今天突然間想試看看 tclsh。我發現…… 對,可以使用同樣的手法。下面就是一個測試的例子:
再來是另外一個簡單的測試:
這樣就可以在命令列執行簡單的 tclsh 命令。
之前我只有在 bash 使用過,今天突然間想試看看 tclsh。我發現…… 對,可以使用同樣的手法。下面就是一個測試的例子:
tclsh - << "EOF"
puts "HELLO World"
EOF
再來是另外一個簡單的測試:
tclsh - << "EOF"
puts [expr 99 + 1]
EOF
這樣就可以在命令列執行簡單的 tclsh 命令。
2019-06-02
Functional Programming
Functional Programming (Tcler's Wiki)
Tcl 是個很奇妙的語言,就如同下面說的:
As with many things, Tcl is rather unique in this area. Commands themselves can not be passed as arguments to other commands, but their names can, which provides something very similar to first-class functions. Additionally, apply can be used to interpret a value as a function and evaluate it, providing the equivalent of lambda functions.
Tcl 的表達方式與波蘭表示法 (Polish notation) 一樣,和 Lisp 的 S-expression 的精神十分相像,特點是操作符置於操作數的前面(就是如果是一連串資料所組合成的述句,Tcl 述句的第一個是一個 command,後面是 command 要處理的資料)。
Tcl 也跟 Lisp 一樣,並不是純粹的 Functional Language,而是支援多重典範的語言。
Tcl 是個很奇妙的語言,就如同下面說的:
As with many things, Tcl is rather unique in this area. Commands themselves can not be passed as arguments to other commands, but their names can, which provides something very similar to first-class functions. Additionally, apply can be used to interpret a value as a function and evaluate it, providing the equivalent of lambda functions.
Tcl 的表達方式與波蘭表示法 (Polish notation) 一樣,和 Lisp 的 S-expression 的精神十分相像,特點是操作符置於操作數的前面(就是如果是一連串資料所組合成的述句,Tcl 述句的第一個是一個 command,後面是 command 要處理的資料)。
Tcl 也跟 Lisp 一樣,並不是純粹的 Functional Language,而是支援多重典範的語言。
2019-05-24
Tcl: 奇數和偶數
#!/usr/bin/env tclsh
puts -nonewline "Please input a number: "
flush stdout
gets stdin var
if { [ regexp {^[0-9]+$} $var ] == 0} {
puts "It is not a number!!!"
exit
}
if { [expr $var % 2] == 0} {
puts "It is even!!!"
} else {
puts "It is odd!!!"
}
也是一個很簡單的練習,只是使用正規表示式判斷是否為數字。
2019-05-21
Tcl:九九乘法表
這只是一個簡單的 Tcl 練習。
所以第一個是 for loop 的版本。
第二個版本是我在寫同樣的東西(也是九九乘法表),因為 Erlang 沒有 for 和 while 迴圈,所以我先建立一個 list,然後再使用 Erlang 提供的 lists:foreach 印出結果。我用同樣的精神寫 Tcl 九九乘法表的第二個版本(同時測試 mathop)。
最後是遞迴的版本:
所以第一個是 for loop 的版本。
#!/usr/bin/env tclsh
for {set nx 0} {$nx < 10} {incr nx} {
for {set ny 0} {$ny < 10} {incr ny} {
puts "[format "%d x %d = %2d" $nx $ny [expr $nx * $ny]]"
}
}
第二個版本是我在寫同樣的東西(也是九九乘法表),因為 Erlang 沒有 for 和 while 迴圈,所以我先建立一個 list,然後再使用 Erlang 提供的 lists:foreach 印出結果。我用同樣的精神寫 Tcl 九九乘法表的第二個版本(同時測試 mathop)。
#!/usr/bin/env tclsh
set x [list 1 2 3 4 5 6 7 8 9]
set y [list 1 2 3 4 5 6 7 8 9]
foreach nx $x {
foreach ny $y {
set z [::tcl::mathop::* $nx $ny]
puts "[format "%d x %d = %2d" $nx $ny $z]"
}
}
最後是遞迴的版本:
#!/usr/bin/env tclsh
namespace path {::tcl::mathop ::tcl::mathfunc}
proc mul {x y} {
puts [format "%d x %d = %2d" $x $y [* $x $y]]
if {$y < 9} {
mul $x [+ $y 1]
} else {
if {$x < 9} {
mul [+ $x 1] 1
} else {
return
}
}
}
mul 1 1
2019-05-13
Next Scripting Framework 2.3.0
ANNOUNCE: Next Scripting Framework 2.3.0 is available
NSF 釋出了 2.3.0,所以我更新了我自己的 openSUSE RPM spec, 這可以比較方便進行測試。我在下載的時候 SourceForge 似乎出現問題,所以無法順利下載,我把下載檔案的地址切到 NSF 在 Github 的 mirror。
NSF 釋出了 2.3.0,所以我更新了我自己的 openSUSE RPM spec, 這可以比較方便進行測試。我在下載的時候 SourceForge 似乎出現問題,所以無法順利下載,我把下載檔案的地址切到 NSF 在 Github 的 mirror。
2019-05-09
2019-04-16
使用 QEMU 執行 openSUSE/AARCH64 image
因為 tclBlend 我接到一個 issue,在 AARCH64 下編譯失敗,所以需要一個 AARCH64 模擬器來除錯。
首先要安裝 QEMU-ARM:
要下載一個 openSUSE AARCH64 image 來進行測試(我使用 unxz 解壓縮)。
如果使用 efi image,需要有 Unified EFI BIOS 模擬器正確的載入 boot loader 才行(不然無法正確執行)。我從 Linaro 下載一個來使用。
然後就可以這樣執行:
(使用者帳號為 root,密碼為 linux)
參考文章:
openSUSE:AArch64
Documentation/Platforms/ARM
Linux on AArch64 ARM 64-bit Architecture
Building ARM Servers With UEFI And ACPI
就 ARM 來說,有二種描述 hardware scheme 的方式,一種是 UEFI/ACPI,一種是 Device Tree。Linux kernel 可以編譯為二種都支援。文件中有提到:
ACPI support in drivers and subsystems for ARMv8 should never be mutually exclusive with DT support at compile time.
At boot time the kernel will only use one description method depending on parameters passed from the boot loader (including kernel bootargs).
Regardless of whether DT or ACPI is used, the kernel must always be capableof booting with either scheme (in kernels with both schemes enabled at compile time).
首先要安裝 QEMU-ARM:
sudo zypper install qemu-arm
要下載一個 openSUSE AARCH64 image 來進行測試(我使用 unxz 解壓縮)。
wget https://download.opensuse.org/ports/aarch64/factory/images/openSUSE-Tumbleweed-ARM-JeOS-efi.aarch64-Current.raw.xz
unxz openSUSE-Tumbleweed-ARM-JeOS-efi.aarch64-Current.raw.xz
如果使用 efi image,需要有 Unified EFI BIOS 模擬器正確的載入 boot loader 才行(不然無法正確執行)。我從 Linaro 下載一個來使用。
wget https://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/QEMU_EFI.img.gz
gzip -d QEMU_EFI.img.gz
然後就可以這樣執行:
qemu-system-aarch64 -m 2048 -cpu cortex-a57 -smp 2 -M virt -bios QEMU_EFI.img -serial stdio -device virtio-net-device,netdev=hostnet0,id=net0,mac=52:54:00:09:a4:37 -netdev user,id=hostnet0 -drive if=none,format=raw,file=openSUSE-Tumbleweed-ARM-JeOS-efi.aarch64-Current.raw,id=hd0 -device virtio-blk-device,drive=hd0
(使用者帳號為 root,密碼為 linux)
參考文章:
openSUSE:AArch64
Documentation/Platforms/ARM
Linux on AArch64 ARM 64-bit Architecture
Building ARM Servers With UEFI And ACPI
就 ARM 來說,有二種描述 hardware scheme 的方式,一種是 UEFI/ACPI,一種是 Device Tree。Linux kernel 可以編譯為二種都支援。文件中有提到:
ACPI support in drivers and subsystems for ARMv8 should never be mutually exclusive with DT support at compile time.
At boot time the kernel will only use one description method depending on parameters passed from the boot loader (including kernel bootargs).
Regardless of whether DT or ACPI is used, the kernel must always be capableof booting with either scheme (in kernels with both schemes enabled at compile time).
2019-04-10
Difference between 2 dates in XQuery
package require xqilla
xqilla db
set exprs [db prepare {days-from-duration(xs:dateTime('2019-06-14T00:00:00') - current-dateTime())}]
set result [$exprs execute]
set diff 0
while {[$result next]} {
set diff [$result string_value]
}
puts "The answer is $diff."
$result close
$exprs close
db close
使用 XQuery 的日期函式計算出二個日期間的差距,這裡使用 XQilla 測試。
訂閱:
文章 (Atom)