在纯函数式编程语言(如Haskell)中,或者只是以函数方式使用它(例如clojure); 假设你有一个整数的list/seq/enumerable(未知大小),你想要生成一个包含连续项之间差异的新list/seq/enumerable,你会怎么做?
我之前在C#中所做的是折叠列表并将状态对象保留为记录"上一个"项目的聚合值,以便您可以从当前项目对其进行差异处理.结果列表也必须进入状态对象(对于未知大小的列表,这是一个问题)
在功能上做这种事情的一般方法是什么?
在clojure中我有这样的行来定义默认值:
(def *http-port* 8080)
Run Code Online (Sandbox Code Playgroud)
我现在决定将这些类型的值正式化为一个配置单元,我想取消定义该值,*http-port*
以便我可以找到仍然引用该值的位置并更改它们以使用新值.换句话说,我正在通过将值移动到不同的位置来进行重构.
我这样做的方法是退出粘液并尝试重新启动粘液会话.在maven的编译阶段,这些错误被拾取,我可以一次找到并修复一个引用.然后我修复错误,冲洗并重复.这显然令人沮丧.
连接到粘液会话时我该怎么做?
我在MS Word中创建了这张图片,我正在尝试使用Documents在我的WPF应用程序中复制样式.首先是"来自":
alt text http://img337.imageshack.us/img337/1275/correntborder.png
接下来我尝试复制:
替代文字http://img156.imageshack.us/img156/1711/extrawhiteborder.png
我的问题可能很明显.我究竟做错了什么?我在行分组或行上找不到填充属性.以下是我的代码:
public override FlowDocument CreateDocumentSection(IInteractivityElement pElement)
{
var result = new FlowDocument();
// show the header
result.Blocks.Add(CreateHeading(pElement.Header));
// we don't show anything else if there aren't any columns
var nrColumns = pElement.GetIntegralData("CurrentColumnCount") ?? 0;
if (nrColumns == 0) return result;
Table mainTable = new Table();
result.Blocks.Add(mainTable);
// columns
for (long tableIdx = 0; tableIdx < nrColumns; tableIdx++)
{
var newColumn = new TableColumn();
mainTable.Columns.Add(newColumn);
}
// row group for header
TableRowGroup rowGroup = …
Run Code Online (Sandbox Code Playgroud) 我有两个宏.第一个将符号作为唯一参数(因为它传递给def,需要一个符号).第二个函数采用符号列表,并应分别使用每个符号调用第一个符号.
(defmacro m1 [s]
'(let [f# ... dynamic function definition ...]
(def ~s f#))
Run Code Online (Sandbox Code Playgroud)
第二个宏应该采用符号列表并将它们传递给第一个,但我无法使它工作.我能想到的最好的是以下内容:
(defmacro m2 [symbols]
`(for [s# ~symbols] (eval (read-string (str "(name.of.current.namespace/m1 " s# ")")))))
Run Code Online (Sandbox Code Playgroud)
它s#
会在传递给第一个宏之前强制进行评估.它还使用字符串列表调用,而不是符号列表.
这对于我正在使用的库非常有用,库中的所有函数都使用相同的两个第一个参数.我试图在我的命名空间中为某些函数创建包装函数,这些函数自动提供所有这些函数共有的前两个参数值.
有什么想法来改善这个吗?
我很难理解为什么我会得到我所看到的行为.我有一段代码,旨在淡出一个容器,替换内容,然后在完成时再次淡入.
我正在使用jQuery,所以代码如下所示:
var transitionToNewContent = function(container, new_content) {
container.fadeOut().delay(1000).empty().append(new_content).fadeIn();
};
transitionToNewContent($('#id'), "<p>magic</p>");
Run Code Online (Sandbox Code Playgroud)
第一次单击激活此转换的链接时,会立即替换内容,然后淡出,然后再次淡入.
每次点击链接后,我都会看到正确的行为:淡出,然后用新内容淡化.
知道为什么会这样吗?
我附上了一个完整的html文件,显示了行为:
我对jquery很新,我正在尝试以正确的方式做事.任何有关风格的评论将不胜感激.
<doctype html>
<html>
<head>
<style type="text/css">
#main_container {
width: 800px;
margin-left: auto;
margin-right: auto;
margin-bottom: 3em;
margin-top: 0;
height: 100%;
position: relative;
top: 0px;
bottom: 0px;
}
#loading {
float: right;
position: relative;
top: 10px;
left: 10px;
z-index: 1;
}
#sidebar {
float: left;
width: 240px;
border: #078600 1px dashed;
position: relative;
top: 10px;
left: -250px;
margin-right: 20px;
background: #cccccc;
z-index: 1;
padding: …
Run Code Online (Sandbox Code Playgroud) 我有一个ItemsControl
数据绑定到ObservableCollection
.我在后面的代码中有这个方法,它在列表中添加了一个新模型.然后我想将新项目(在列表底部)滚动到视图中.
ItemsControl
当我查询大小时,我认为它的大小尚未更新,因为ActualHeight
模型的添加之前和之后是相同的.此代码的效果是滚动到略高于新项目的点.
我怎么知道新的东西ActualHeight
会是什么?
这是我的代码:
ViewModel.CreateNewChapter();
var height = DocumentElements.ActualHeight;
var width = DocumentElements.ActualWidth;
DocumentElements.BringIntoView(new Rect(0, height - 1, width, 1));
Run Code Online (Sandbox Code Playgroud) 我有以下路线定义:
(require '[compojure.core :as ccore]
'[ring.util.response :as response])
(def *main-routes*
(ccore/defroutes avalanche-routes
(ccore/GET "/" [] "Hello World 2")
(ccore/GET "/images/:id" [id] (get-image-response id))))
Run Code Online (Sandbox Code Playgroud)
在此示例中,请求/
像魅力一样工作并返回预期的Hello World 2
.
get-images-response方法定义如下:
(defn get-image-response
[id]
(let [record (db/get-image id false)]
(-> (response/response (:data record))
(response/content-type (:content-type record))
(response/header "Content-Length" (:size record)))))
Run Code Online (Sandbox Code Playgroud)
虽然我得到了404,但是二进制文件的服务还没有完成.有什么想法吗?
编辑:好的,问题与正在请求图像的事实有关/images/name.jpg
.一旦我删除.jpg
了处理程序被调用.所以问题是如何匹配除扩展名之外的任何内容?
在核心命名空间的compojure库中,我看到以下形式:
(defn- compile-route
"Compile a route in the form (method path & body) into a function."
[method route bindings body]
`(#'if-method ~method
(#'if-route ~(prepare-route route)
(fn [request#]
(let-request [~bindings request#]
(render (do ~@body) request#))))))
Run Code Online (Sandbox Code Playgroud)
和
(defmacro GET "Generate a GET route."
[path args & body]
(compile-route :get path args body))
Run Code Online (Sandbox Code Playgroud)
进一步在文件中,if-method
和if-route
函数用defn-
s 定义.
我不明白#'
这个compile-route
功能的含义.文档(var ...)
说:
符号必须解析为var,并返回Var对象本身(而不是其值).读者宏#'x扩展为(var x).
但对我而言,在正在发生的事情的背景下(即从defmacro调用),它只是意味着它将返回符号的价值,这与可替代性听起来是一样的:
(def x 5)
(+ x 7)
-> …
Run Code Online (Sandbox Code Playgroud) 我有以下XAML:
<DockPanel x:Name="OverViewContainer" AllowDrop="True">
<StackPanel Orientation="Horizontal"
DockPanel.Dock="Bottom"
HorizontalAlignment="Right">
<uicommon:Toolbar DataContext="{Binding Commands}" />
</StackPanel>
<ItemsControl ItemsSource="{Binding DocumentElements}"
ItemTemplate="{DynamicResource DocumentElementsItemTemplate}" />
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
当我将数据拖到此面板上时,鼠标光标显示所有子项都允许删除,但在任何空白空间上,光标显示已禁用删除.如果我设置AllowDrop
为false,我不能再删除子项,因此标志DOES有效.我想将数据放入到项目中的边距之间ItemsControl
.
有任何想法吗?
clojure ×5
wpf ×3
itemscontrol ×2
binary-data ×1
c# ×1
compojure ×1
data-binding ×1
datatemplate ×1
document ×1
formatting ×1
haskell ×1
interactive ×1
javascript ×1
jquery ×1
jquery-ui ×1
macros ×1
namespaces ×1
ntfs ×1
ocaml ×1
slime ×1