a = [1, 2, 3]
a.each do |x| x+=10 end
Run Code Online (Sandbox Code Playgroud)
在此操作之后,阵列a仍然是[1, 2, 3].如何将其转换为[11, 12, 13]?
我想制作几个面板的窗口.我可以将一个附加到MainFrame的内容:import swing._
class View(model:Model) extends MainFrame {
title = "app"
val parameters = new FlowPanel() {
contents += new Label("Tempo: ")
contents += new ComboBox(Seq("80", "100", "120", "140"))
contents += new Label("Metric: ")
contents += new Label("Note: ")
}
contents = parameters
}
Run Code Online (Sandbox Code Playgroud)
但是当我试图追加另一个时:
class View(model:Model) extends MainFrame {
title = "app"
val parameters = new FlowPanel() {
contents += new Label("Tempo: ")
contents += new ComboBox(Seq("80", "100", "120", "140"))
contents += new Label("Metric: ")
contents += new Label("Note: ") …Run Code Online (Sandbox Code Playgroud) 这是我的代码(几乎完整版@cdhowie :)):
def getResult(method, argument=None):
result = None
while True:
print('### loop')
try:
print ('### try hard...')
if argument:
result = method(argument)
else:
result = method()
break
except Exception as e:
print('### GithubException')
if 403 == e.status:
print('Warning: ' + str(e.data))
print('I will try again after 10 minutes...')
else:
raise e
return result
def getUsernames(locations, gh):
usernames = set()
for location in locations:
print location
result = getResult(gh.legacy_search_users, location)
for user in result:
usernames.add(user.login)
print user.login,
return usernames
# "main.py" …Run Code Online (Sandbox Code Playgroud) 我有这样的dir层次结构:
src
src/Model
src/View
src/Controller
Run Code Online (Sandbox Code Playgroud)
现在我想构建我的应用程序.如何从模型视图和控制器导入/包含类,因为编译器无法看到它们?
//编辑
SRC/App.scala
import swing._
object App extends Application {
val model = new Model
val view = new View(model)
val controller = new Controller(model, view)
view.visible = true
}
Run Code Online (Sandbox Code Playgroud)
SRC /型号/ Model.scala
class Model {
// some code
}
Run Code Online (Sandbox Code Playgroud)
SRC /查看/ View.scala
import swing._
class View(model:Model) extends MainFrame {
// some code
}
Run Code Online (Sandbox Code Playgroud)
SRC /控制器/ Controller.scala
class Controller(model:Model, view:View) {
// some code
}
Run Code Online (Sandbox Code Playgroud)
这是一个构建脚本
#!/bin/bash
source ${0%/*}/config.inc.sh
if [ ! -d $CLASSES_PATH ]; …Run Code Online (Sandbox Code Playgroud) 可能重复:
C动态增长的数组
我有一个程序,我需要从文件中读取浮点数.每行是一个浮点数.问题是这个文件可能非常大
float tab[1000];
f = fopen ("data.txt", "r");
i=0;
while (feof(f) == 0) {
fscanf (f, "%f\n", &tab[i]);
i++;
}
Run Code Online (Sandbox Code Playgroud)
如果它太小,我怎么能动态改变数组的大小呢?
我有这个功能,负责网络聊天中的通信.一切正常没有t <- getClockTime(这里是代码):
talk :: WS.Protocol p => MVar State -> Client -> WS.WebSockets p ()
talk state client@(user, sink) = flip WS.catchWsError catchDisconnect $
forever $ do
t <- getClockTime
msg <- WS.receiveData
case () of
() | T.unpack(msg) == "#list" -> liftIO $ readMVar state >>= listClients client
| T.unpack(msg) == "#time" -> liftIO (sendTime client)
| "#name" `T.isPrefixOf` msg -> liftIO (command msg client)
| otherwise -> liftIO $ readMVar state >>= broadcast
(user `mappend` …Run Code Online (Sandbox Code Playgroud)