小编cod*_*e4j的帖子

如何在mac上安装make和gcc?

我想在我的macbook air(2011版)上安装Eclim.但是在安装过程中我遇到了一些问题.它告诉我,我没有安装make和gcc.

我试图找到它的解决方案,但所有解决方案都在谈论使用XCode.实际上,我安装了XCode.但我仍然无法安装Eclim,因为没有安装make和gcc.

如何安装它们才能安装Eclim?

gcc makefile eclim osx-lion

26
推荐指数
2
解决办法
4万
查看次数

电力线可以显示在多个缓冲区中,但不能显示在单个缓冲区中

我刚刚使用病原体和子模块将Powerline插件安装到我的vim中.

多个缓冲区位于何处时,电源线才可见.当vim中只有一个缓冲区时,我看不到它.

我想知道它是不是一个bug?

单 VEC 奥斯

vim macvim vim-plugin

25
推荐指数
1
解决办法
2738
查看次数

如何验证关联的模型ID?

我有一个学生和一个课程模型.学生属于课程,课程有很多学生.

class Student < ActiveRecord::Base
  attr_accessible :course_id, :name, :password, :status, :studentID, :year
  belongs_to :course

  validates :name, :password, :status, :studentID, :year, :presence =>true
  validates_associated :course
end

class Course < ActiveRecord::Base
  attr_accessible :courseCode, :courseName, :courseYr
  validates :courseCode,:courseName,:courseYr, :presence => true
  validates :courseCode,:courseYr, :uniqueness=>{:message=>"Cannot repeat the code"}

  has_many :students 
end
Run Code Online (Sandbox Code Playgroud)

在用于创建学生记录的表单中,我让用户输入课程ID.

<div class="field">
  <%= f.label :course_id %><br />
  <%= f.text_field :course_id %>
</div>
Run Code Online (Sandbox Code Playgroud)

但我不知道如何验证course_id用户的输入.即使我键入不存在的课程ID,学生模型验证也不会生成错误.如何让它显示错误?

ruby activerecord ruby-on-rails

12
推荐指数
1
解决办法
8251
查看次数

什么!()在数据构造函数中意味着什么?

我正在阅读Data.Map的源代码,我发现!()用于数据构造函数中data Map k a.

data Map k a  = Tip 
              | Bin {-# UNPACK #-} !Size !k a !(Map k a) !(Map k a) 
Run Code Online (Sandbox Code Playgroud)

我发现这!( )不会影响patten如何匹配数据.在mapWithKey的功能中,模式匹配仍然适用于5件事.所以我不认为它是一个运营商.

mapWithKey f (Bin sx kx x l r) 
Run Code Online (Sandbox Code Playgroud)

谷歌后,我发现!( )可能与-XBangPatterns懒惰评估有关.我对吗 ?还是出于其他目的?

haskell map

11
推荐指数
1
解决办法
434
查看次数

我可以通过评估字符串在运行时创建函数吗?

在我解决离散数学的程序中,我想让用户输入一串逻辑运算; 例如,如果用户输入let f (x:y:_) = x && y,那么我将得到一个功能,f用于该程序的其余部分.在GHCi中,我可以通过输入轻松测试我的程序let f (x:y:_) = x && y.

我不知道如何完成这项任务.我已经evalplugins包中看了一下这个函数,但它似乎不是正确的函数.我可以在Haskell中这样做吗?

我计划使用它的代码是:

type TruthTable = [[Bool]]
type TruthTableResult = [([Bool], Bool)]

solveTable :: ([Bool] -> Bool) -> Integer -> (TruthTableResult)
solveTable f n = let table = truthTable n
                     result = map f table
                 in  zipWith (\v r -> (v, r)) table result
Run Code Online (Sandbox Code Playgroud)

haskell eval

9
推荐指数
3
解决办法
1323
查看次数

如何简化嵌套 - 如果使用在Haskell中返回值

我想检查前一个的条件,if condition以确定下一个if condition是否要执行.每个人都if condition可以返回一个值.

编辑:对不起,我之前提供的例子有些奇怪... :(这是我真实的例子,我想简化if-then-elsegoingToMove

goingToMove p routes points w h = 
                        if canMove p points
                            -- the point can be moved in the map 
                            then let r = routes ++ [p]
                                     l = remainList p points
                                in move p r l w h
                            -- the point cannot be moved in the maps
                            else []

move p routes points w h = 
            if (length routes) == 2 
                then routes
                else …
Run Code Online (Sandbox Code Playgroud)

recursion haskell functional-programming if-statement tail-recursion

7
推荐指数
2
解决办法
2044
查看次数

如何编写一个可以轻松维护的概率算法?

假设我想创造一个游戏.在游戏开始时,玩家将挑选一个怪物.

公平地挑选怪物很容易.

// get all monsters with equal chance
public Monster getMonsterFair(){
    Monster[] monsters = {new GoldMonster(), new SilverMonster(), new BronzeMonster()};
    int winIndex = random.nextInt(monsters.length);
    return monsters[winIndex];
}
Run Code Online (Sandbox Code Playgroud)

并不公平地挑选怪物.

// get monsters with unequal chance
public Monster getMonsterUnFair(){
    double r = Math.random();
    // about 10% to win the gold one
    if (r < 0.1){
        return new GoldMonster();
    }
    // about 30% to winthe silver one
    else if ( r < 0.1 + 0.2){
        return new SilverMonster();
    }
    // about 70% …
Run Code Online (Sandbox Code Playgroud)

java algorithm maintainability refactoring

7
推荐指数
1
解决办法
1260
查看次数

为什么haskell使用一种ReadS来表示一个函数?

我正在阅读的源代码reads.reads被定义为reads :: Read a => ReadS a 它只是返回ReadS a而a必须是一个实例Read.

并且ReadS a被定义为type ReadS a = String -> [(a, String)],所以返回的东西reads只是一个函数,它接受一个字符串并返回一个元组数组.

然后我想知道为什么reads没有ReadS 定义a.就像 reads :: Read a => (String -> [(a, String)])

haskell function

5
推荐指数
1
解决办法
185
查看次数

是否兼容使用iOS SDK 6.0开发iOS 5.1应用程序

我刚刚将我的XCode升级到4.5并安装了SDK 6.0.我发现SDK 5.0消失但我仍然可以下载回Iphone 5.0模拟器.

我只是想知道天气我可以使用SDK 6.0开发iOS 5.1应用程序.我已经进行了如下图所示的配置.

在此输入图像描述 在此输入图像描述

iphone xcode ios ios5 ios6

4
推荐指数
1
解决办法
2101
查看次数

如何实现Eq类型类函数:x == y = not(x/= y)x/= y = not(x == y)工作?

我正在读这本书,它谈到了类型类的定义Eq

在Eq中有两个函数==,/=它们实现为:

  x == y = not (x /= y)  
  x /= y = not (x == y)  
Run Code Online (Sandbox Code Playgroud)

书中说它们是相互递归的,函数的结果是在另一个函数的项目中.

我不明白的是我在相互递归中没有看到基本情况,我不明白为什么函数会停止并返回结果.

recursion haskell typeclass mutual-recursion

4
推荐指数
1
解决办法
169
查看次数