我想我理解在Clojure交易中通勤和改变的想法之间的基本区别.
更改基本上从事务的开始到结束"锁定"身份,以便多个事务必须按顺序执行.
Commute仅将锁应用于身份的实际值更改,以便事务中的其他操作可以在不同的时间运行,并具有不同的世界视图.
但我对某些事感到困惑.让我们定义一个带有副作用的函数和一个参与的函数:
(defn fn-with-side-effects [state]
(println "Hello!")
(inc state))
(def test-counter (ref 0))
Run Code Online (Sandbox Code Playgroud)
现在,如果我们使用alter,我们会看到预期的行为:
user=> (dosync (alter test-counter fn-with-side-effects))
Hello!
1
Run Code Online (Sandbox Code Playgroud)
但是如果我们使用通勤:
user=> (dosync (ref-set test-counter 0))
0
user=> (dosync (commute test-counter fn-with-side-effects))
Hello!
Hello! ; hello is printed twice!
1
Run Code Online (Sandbox Code Playgroud)
因此在通勤版本中,该函数显然仅修改ref一次,因为最终值为1.但是修改器函数的副作用执行两次.为什么会这样?
我几天前升级到El Capitan并跑了一个
brew update && brew upgrade
Run Code Online (Sandbox Code Playgroud)
它更新了imagemagick,导致ruby的rmagick gem停止工作.
没问题,我想,我会跑
gem install rmagick
Run Code Online (Sandbox Code Playgroud)
它会重新编译.
除了它没有,当我运行它时,我看到:
gem install rmagick
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/Users/sam/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151019-57347-30ju1w.rb extconf.rb
checking for clang... yes
checking for Magick-config... yes
checking for outdated ImageMagick version (<= 6.4.9)... no
checking for Ruby version >= 1.8.5... yes
checking for stdint.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably …Run Code Online (Sandbox Code Playgroud) 调试测试可以完美工作,但最近某个时候发生了一些变化,现在却没有(也许是 go 版本升级?)。
当我单击“调试测试”时,会弹出此错误消息:
错误是:Failed to launch: invalid debug configuration - cannot unmarshal bool into "env" of type string
我的launch.json看起来不错(同样,这曾经完美地工作过):
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}",
"env": {
"LOG_LEVEL": "debug",
"LOG_SQL": "false",
"DATABASE_URL": "postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable",
},
"args": ["-v"]
},
]
Run Code Online (Sandbox Code Playgroud)
}
可能出什么问题了?
我无法在Google或stackoverflow上的任何其他位置找到此确切错误.
我正在运行Rails 4.1.0和rspec-rails 3.0.0.beta2
尝试运行$ rspec时,出现以下错误:
DEPRECATION WARNING: Passing a string to ActiveRecord::Base.establish_connection for a configuration lookup is deprecated, please pass a symbol (:development) instead. (called from <top (required)> at /Users/sam/code/rails/innovacert/spec/spec_helper.rb:4)
/Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:257:in `resolve_symbol_connection': 'development' database is not configured. Available: ["test"] (ActiveRecord::AdapterNotSpecified)
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:240:in `resolve_string_connection'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:267:in `resolve_hash_connection'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:228:in `resolve_connection'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:152:in `resolve'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:164:in `block in resolve_all'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:163:in `each'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:163:in `resolve_all'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_handling.rb:69:in `resolve'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/core.rb:46:in `configurations='
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/core.rb:48:in `block in <module:Core>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/concern.rb:120:in `class_eval'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/concern.rb:120:in …Run Code Online (Sandbox Code Playgroud) 我正在尝试运用K&R的2.1.练习内容如下:
写一个程序,以确定的范围
char,short,int,和long变量,都signed和unsigned通过打印从标准头合适的值,并通过直接计算.如果计算它们会更难:确定各种浮点类型的范围.
打印标准标题中常量的值很简单,就像这样(例如只显示整数):
printf("Integral Ranges (from constants)\n");
printf("int max: %d\n", INT_MAX);
printf("int min: %d\n", INT_MIN);
printf("unsigned int max: %u\n", UINT_MAX);
Run Code Online (Sandbox Code Playgroud)
但是,我想以编程方式确定限制.
我尝试了这个代码似乎应该可以工作,但它实际上进入一个无限循环并被卡在那里:
printf("Integral Ranges (determined programmatically)\n");
int i_max = 0;
while ((i_max + 1) > i_max) {
++i_max;
}
printf("int max: %d\n", i_max);
Run Code Online (Sandbox Code Playgroud)
为什么这会陷入循环?似乎当整数溢出时,它会从2147483647跳转到-2147483648.递增的值显然小于先前的值,因此循环应该结束,但它不会.
我有模板代码,如下所示:
<%= form_for @changeset, @action, fn f -> %>
<%= if Enum.any?(f.errors) do %>
<%= for {attr, message} <- f.errors do %>
<li><%= humanize(attr) %> <%= message %></li>
<% end %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但即使更改集包含错误,也不会打印错误.这是检查的表单结构.请注意,即使错误列表是根据更改集生成的,但错误列表仍为空.
%Phoenix.HTML.Form{data: %BlogPhoenix.Comment{__meta__: #Ecto.Schema.Metadata<:built, "comments">,
content: nil, id: nil, inserted_at: nil, name: nil, post_id: nil,
posts: #Ecto.Association.NotLoaded<association :posts is not loaded>,
updated_at: nil}, errors: [], hidden: [], id: "comment",
impl: Phoenix.HTML.FormData.Ecto.Changeset, index: nil, name: "comment",
options: [method: "post"],
params: %{"content" => nil, "name" …Run Code Online (Sandbox Code Playgroud)