我关掉了ARC.
我在这样声明的类中有一个属性:
@property(copy) NSString* name
Run Code Online (Sandbox Code Playgroud)
我name用常量字符串设置:
[greeter setName:@"Jane"];
Run Code Online (Sandbox Code Playgroud)
我dealloc为我的班级实现了这样的:
-(void)dealloc{
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
我预计会有内存泄漏,因为我没有发布name.我正在使用Xcode 6.2并且Product>Analyze没有识别任何泄漏,仪器也没有:Product>Profile, choose Leaks, hit the red Record button.
这是相关代码:
//
// Greeter.h
// Flashlight2
//
#import <Foundation/Foundation.h>
@interface Greeter : NSObject
@property(copy) NSString* name;
-(NSString*)description;
-(void)dealloc;
@end
Run Code Online (Sandbox Code Playgroud)
....
//
// Greeter.m
// Flashlight2
//
#import "Greeter.h"
@implementation Greeter
-(NSString*)description {
NSString* msg = [[NSString alloc] initWithString:@"I am a Greeter"];
return [msg autorelease];
}
-(void)dealloc{
[super dealloc]; …Run Code Online (Sandbox Code Playgroud) 在List 类的文档中,它说:
routine map
multi method map(Hash:D \hash)
multi method map(Iterable:D \iterable)
multi method map(|c)
multi method map(\SELF: █; :$label, :$item) multi sub map(&code, +values)
multi sub map(&code, +values)
Run Code Online (Sandbox Code Playgroud)
在第一个多方法子句中,我认为签名表示该方法采用一个参数,该参数是 Hash 类 (Hash:D) 的实例。该参数将被分配给一个无符号变量 \hash (这是一个常量),这意味着您知道调用者中的哈希值不能被该方法更改。
根据方法名称、映射和哈希参数,哈希似乎会将列表的元素映射到哈希中的相应值。我们来尝试一下:
[106] > my %hash = %{1 => 'apple', 2 => 'tree', 3 => 'octopus'};
{1 => apple, 2 => tree, 3 => octopus}
[107] > (1, 2, 3).map(%hash);
Cannot map a List using a Hash
Did you mean to add a stub …Run Code Online (Sandbox Code Playgroud) data.txt中:
hello world
goodbye mars
goodbye perl6
hello perl5
Run Code Online (Sandbox Code Playgroud)
myprog.py:
my $fname = 'data.txt';
my $infile = open($fname, :r, nl => "\n\n");
for $infile.lines(nl => "\n\n") -> $para {
say $para;
say '-' x 10;
}
Run Code Online (Sandbox Code Playgroud)
实际产量:
hello world
----------
goodbye mars
----------
----------
goodbye perl6
----------
back to perl5
----------
Run Code Online (Sandbox Code Playgroud)
期望的输出:
hello world
goodbye mars
-----------
goodbye perl6
back to perl5
-----------
Run Code Online (Sandbox Code Playgroud)
...
$ perl6 -v
This is perl6 version 2015.03-21-gcfa4974 built on MoarVM version 2015.03
Run Code Online (Sandbox Code Playgroud) 我检查了一下rebar,但这似乎太复杂了.也许有人可以%Post your code here在以下钢筋应用程序中发布一些内容:
%%%-------------------------------------------------------------------
%% @doc myapp public API
%% @end
%%%-------------------------------------------------------------------
-module('myapp_app').
-behaviour(application).
%% Application callbacks
-export([start/2
,stop/1]).
%%====================================================================
%% API
%%====================================================================
start(_StartType, _StartArgs) ->
'myapp_sup':start_link().
%%--------------------------------------------------------------------
stop(_State) ->
ok.
Run Code Online (Sandbox Code Playgroud)
是否有一些更容易的替代初学者?
我预计将 Any 类型细化为 Str|True 将使name类型与任何 Str 或 True 匹配,但这就是我所看到的:
subset name of Any where Str|True;\n\nsub go(name :$x) {\n say $x;\n}\n\ngo(x => "hello"); #hello\ngo(x => True); #True\n\ngo(x => 2); #2\nmy @arr = 1, 2, 3; \ngo(x => @arr); #[1, 2, 3]\nRun Code Online (Sandbox Code Playgroud)\n如果我将子集更改为subset name of Any where Str|Bool,那么它会按我的预期工作:
subset name of Any where Str|Bool;\n\nsub go(name :$x) {\n say $x;\n}\n\ngo(x => "hello"); \ngo(x => True); \ngo(x => False);\n\ngo(x => 2);\n\n--output:--\nhello\nTrue\nFalse\nConstraint type check failed in binding to …Run Code Online (Sandbox Code Playgroud) 这对我来说似乎很疯狂:
use v6.d;
say "Before division by zero!";
my $result = divide(3, 0);
say "After division by zero!";
sub divide($a, $b) {
my $result;
$result = $a / $b; # Line 11
return $result;
}
sub go($x) {
say "hello";
say $x; # Line 17
}
go($result); # Line 20
--output:--
Before division by zero!
After division by zero!
hello
Attempt to divide by zero when coercing Rational to Str
in sub go at b.raku line 17
in block <unit> …Run Code Online (Sandbox Code Playgroud) 谁能解释一下:
~$ echo $PGDATA
/Library/PostgreSQL/9.2/data
~$ cd /Library/PostgreSQL/9.2/
/Library/PostgreSQL/9.2$ sudo su postgres
bash-3.2$ echo $PGDATA
<blank line>
bash-3.2$ pg_ctl start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
bash-3.2$ export PGDATA="/Library/PostgreSQL/9.2/data"
bash-3.2$ pg_ctl start
server starting
bash-3.2$
Run Code Online (Sandbox Code Playgroud)
以下是我的 ~/.bashrc 文件:
export PGDATA="/Library/PostgreSQL/9.2/data"
Run Code Online (Sandbox Code Playgroud)
我没有拼错 PGDATA 中的路径:
~$ echo $PGDATA
/Library/PostgreSQL/9.2/data
export PGDATA="/Library/PostgreSQL/9.2/data"
Run Code Online (Sandbox Code Playgroud) 给定一个正数 N,我的 print_even() 函数打印出 1 到 N 之间的所有偶数:
-module(my).
-compile(export_all).
print_even(N) when N>0 -> even_helper(1, N).
even_helper(Current, N) when Current =< N ->
io:format("(Current = ~w)~n", [Current]),
case Current rem 2 of
0 -> io:format("Number: ~p~n", [Current]);
_ -> do_nothing
end,
even_helper(Current+1, N);
even_helper(Current, N) when Current > N ->
ok.
Run Code Online (Sandbox Code Playgroud)
这是一些示例输出:
28> my:print_even(10).
(Current = 1)
(Current = 2)
Number: 2
(Current = 3)
(Current = 4)
Number: 4
(Current = 5)
(Current = 6)
Number: 6
(Current = …Run Code Online (Sandbox Code Playgroud) 我按照Cowboy 的入门说明进行操作,让 Cowboy 在端口 8080 上运行和侦听,当我在浏览器中Hello Erlang!输入时,我得到了响应。http://localhost:8080现在,如何使用 Gun 连接到 Cowboy?
我阅读了Gun 文档,它说添加“Gun 作为 erlang.mk 依赖项”。所以我下载了erlang.mk:
~/erlang_programs/my_gun$ curl -O https://erlang.mk/erlang.mk
Run Code Online (Sandbox Code Playgroud)
并按照Erlang.mk 用户指南,我创建了一个应用程序:
~/erlang_programs/my_gun$ gmake -f erlang.mk bootstrap
Run Code Online (Sandbox Code Playgroud)
然后我将 Gun 作为依赖项添加到 Makefile 中:
PROJECT = my_gun
PROJECT_DESCRIPTION = New project
PROJECT_VERSION = 0.1.0
DEPS = gun
include erlang.mk
Run Code Online (Sandbox Code Playgroud)
然后我编译了:
~/erlang_programs/my_gun$ gmake
gmake[1]: Entering directory '/Users/7stud/erlang_programs/my_gun/deps/gun'
gmake[2]: Entering directory '/Users/7stud/erlang_programs/my_gun/deps/cowlib'
ERLC cow_cookie.erl cow_date.erl cow_hpack.erl cow_http.erl cow_http2.erl cow_http_hd.erl cow_http_te.erl cow_mimetypes.erl cow_multipart.erl cow_qs.erl cow_spdy.erl cow_sse.erl …Run Code Online (Sandbox Code Playgroud) 示例1:
#!/usr/bin/env raku
use v6.d;
sub MAIN(Int $int) {
say 'parameter $int: ', $int.^name;
}
--output:--
$ raku b.raku 10
parameter $int: IntStr
Run Code Online (Sandbox Code Playgroud)
示例2:
#!/usr/bin/env raku
use v6.d;
sub MAIN(Str $str) {
say 'parameter $str: ', $str.^name;
}
--output:--
$ raku b.raku 10
parameter $str: IntStr
$ raku b.raku hello
parameter $str: Str
$ raku b.raku 10hello
parameter $str: Str
$ raku b.raku 6.5
parameter $str: RatStr
Run Code Online (Sandbox Code Playgroud)
示例3:
#!/usr/bin/env raku
use v6.d;
multi sub MAIN(Int $int) {
say 'parameter $int: …Run Code Online (Sandbox Code Playgroud) raku ×5
erlang ×3
cowboy ×1
debugging ×1
file ×1
io ×1
ios8 ×1
memory-leaks ×1
objective-c ×1
perl6 ×1
postgresql ×1