mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
ch1.2: 删除废弃代码
This commit is contained in:
parent
b3e35dd932
commit
46d71f3b13
@ -1,10 +0,0 @@
|
|||||||
// ch1.2-1
|
|
||||||
|
|
||||||
main() {
|
|
||||||
extrn a, b, c;
|
|
||||||
putchar(a); putchar(b); putchar(c);
|
|
||||||
putchar('!*n');
|
|
||||||
}
|
|
||||||
a 'hell';
|
|
||||||
b 'o, w';
|
|
||||||
c 'orld';
|
|
@ -1,10 +0,0 @@
|
|||||||
// chai2010.cn/gobook/examples/ch1.2-10
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
func main() int {
|
|
||||||
print "hello, world\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
// chai2010.cn/gobook/examples/ch1.2-11
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
print "hello, world\n";
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
// go run chai2010.cn/gobook/examples/ch1.2-12
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
print("hello, world\n")
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
// go run chai2010.cn/gobook/examples/ch1.2-13
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.printf("hello, world\n")
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
// go run chai2010.cn/gobook/examples/ch1.2-14
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Printf("hello, world\n") // ;
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
// go run chai2010.cn/gobook/examples/ch1.2-15
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Printf("hello, world\n")
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
// go run chai2010.cn/gobook/examples/ch1.2-16
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("Please visit http://127.0.0.1:12345/")
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
|
||||||
s := fmt.Sprintf("你好, 世界! -- Time: %s", time.Now().String())
|
|
||||||
fmt.Fprintf(w, "%v\n", s)
|
|
||||||
log.Printf("%v\n", s)
|
|
||||||
})
|
|
||||||
if err := http.ListenAndServe(":12345", nil); err != nil {
|
|
||||||
log.Fatal("ListenAndServe: ", err)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
// ch1.2-2
|
|
||||||
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
printf("hello, world");
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
// ch1.2-3
|
|
||||||
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
printf("hello, world\n");
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
// ch1.2-4
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
printf("hello, world\n");
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
// ch1.2-5
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
main(void)
|
|
||||||
{
|
|
||||||
printf("hello, world\n");
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
// ch1.2-6
|
|
||||||
|
|
||||||
print("Hello,", "World", "\n");
|
|
@ -1,43 +0,0 @@
|
|||||||
// ch1.2-7
|
|
||||||
|
|
||||||
// 向管道输出从2开始的自然数序列
|
|
||||||
counter := prog(c:chan of int) {
|
|
||||||
i := 2;
|
|
||||||
for(;;) {
|
|
||||||
c <-= i++;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 针对listen管道获取的数列,过滤掉是prime倍数的数
|
|
||||||
// 新的序列输出到send管道
|
|
||||||
filter := prog(prime:int, listen, send:chan of int) {
|
|
||||||
i:int;
|
|
||||||
for(;;) {
|
|
||||||
if((i = <-listen)%prime) {
|
|
||||||
send <-= i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 主函数
|
|
||||||
// 每个管道第一个流出的数必然是素数
|
|
||||||
// 然后基于这个新的素数构建新的素数过滤器
|
|
||||||
sieve := prog() of chan of int {
|
|
||||||
c := mk(chan of int);
|
|
||||||
begin counter(c);
|
|
||||||
prime := mk(chan of int);
|
|
||||||
begin prog(){
|
|
||||||
p:int;
|
|
||||||
newc:chan of int;
|
|
||||||
for(;;){
|
|
||||||
prime <-= p =<- c;
|
|
||||||
newc = mk();
|
|
||||||
begin filter(p, c, newc);
|
|
||||||
c = newc;
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
become prime;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 启动素数筛
|
|
||||||
prime := sieve();
|
|
@ -1,21 +0,0 @@
|
|||||||
// ch1.2-8
|
|
||||||
|
|
||||||
#include <alef.h>
|
|
||||||
|
|
||||||
void receive(chan(byte*) c) {
|
|
||||||
byte *s;
|
|
||||||
s = <- c;
|
|
||||||
print("%s\n", s);
|
|
||||||
terminate(nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(void) {
|
|
||||||
chan(byte*) c;
|
|
||||||
alloc c;
|
|
||||||
proc receive(c);
|
|
||||||
task receive(c);
|
|
||||||
c <- = "hello proc or task";
|
|
||||||
c <- = "hello proc or task";
|
|
||||||
print("done\n");
|
|
||||||
terminate(nil);
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
// ch1.2-9
|
|
||||||
|
|
||||||
implement Hello;
|
|
||||||
|
|
||||||
include "sys.m"; sys: Sys;
|
|
||||||
include "draw.m";
|
|
||||||
|
|
||||||
Hello: module
|
|
||||||
{
|
|
||||||
init: fn(ctxt: ref Draw->Context, args: list of string);
|
|
||||||
};
|
|
||||||
|
|
||||||
init(ctxt: ref Draw->Context, args: list of string)
|
|
||||||
{
|
|
||||||
sys = load Sys Sys->PATH;
|
|
||||||
sys->print("hello, world\n");
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user