考虑这个javascript:
function addX(n)
{
return 3 + n;
}
alert(addX(6)); //alerts 9
eval('var newFunc = ' + addX.toString().replace("3", "5") + ';');
alert(newFunc(10)); //alert 15
Run Code Online (Sandbox Code Playgroud)
请忽略这样一个事实:它使用和方法可疑,危险,难以在大型代码库中使用,等等.它允许您根据用户的输入动态修改功能.我没有证明,但我也很容易.
我希望你能告诉我如何在lisp中做到这一点.我已经阅读了很多教程,阅读了很多关于宏的内容,提出了一个更广泛的问题,尝试了很多东西,但最终还是做得很短.
我想知道,在lisp中,我可以在运行时修改此函数,而不是添加5.或者用户可能输入的任何其他内容.
(define (addX n)
(+ 3 n))
Run Code Online (Sandbox Code Playgroud)
我不是在寻找currying!我知道我可以这样做:
(define addXCurry
(lambda (x)
(lambda (n)
(+ x n))))
(define add5 (addXCurry 5))
(add5 10)
Run Code Online (Sandbox Code Playgroud)
但这是在创建一个功能工厂.
我正在使用一个简单的例子,因为我想完全理解一些简单的东西.
编辑 谢谢大家的答案.我想我围绕宏的大笨蛋(据我所知),是因为我没有看到一个完全将修改与写作分开的东西.javascript示例很简单 - 但您可以根据用户输入执行更复杂的重写.
我见过的宏都是基于"编译时"(或者我编写的程序员编写的时间).就像在C++中一样,您不能拥有动态模板参数 - 必须在编译时知道它.
(看起来)在lisp中,你无法在运行时根据javascript中的方式从根本上改变过程,因为你丢失了源代码.您可以评估并重新定义它,但不能遍历列表的元素(列表是函数定义),检查每个元素并决定是否更改它.例外情况似乎是Rainer答案中的例子,这些例子都是不稳定的.
在垂直对齐的表格单元格中:底部,我有一个或两个div.每个div都是浮动的.
据说,div不应该与底部对齐,但它们确实(我不明白,但是很好).
但是,当我在单元格中有两个浮动div时,它们将自己对齐到相同的顶行.
我想让第一个较小的div一直坐在底部.另一种可接受的解决方案是使其成为表格单元的全高度.
这很难解释,所以这里是代码:
Run Code Online (Sandbox Code Playgroud)<style type="text/css"> table { border-collapse: collapse; } td { border:1px solid black; vertical-align:bottom; } .h { float:right; background: #FFFFCC; } .ha { float:right; background: #FFCCFF; } </style> <table> <tr> <td> <div class="ha">@</div> <div class="h">Title Text<br />Line 2</div> </td> <td> <div class="ha">@</div> <div class="h">Title Text<br />Line 2<br />Line 3</div> </td> <td> <div class="h">Title Text<br />Line 2</div> </td> <td> <div class="h">Title Text<br />Line 2</div> </td> <td> <div class="h">Title Text<br />Line 2</div> </td> </tr> <tr> <td> <div class="d">123456789</div> …
Run Code Online (Sandbox Code Playgroud)List<tinyClass> ids = new List<tinyClass(); ids.Add(new tinyClass(1, 2)); bool b = ids.IndexOf(new tinyClass(1, 2)) >= 0; //true or false?
如果按值进行比较,则应返回true; 如果通过引用,它将返回false.
如果它通过引用进行比较,我将tinyClass作为一个结构 - 这会有所作为吗?
症状:
Disagnosing.我已按照以下步骤记录IIS中的关闭:
我知道这些都有效,因为......
我在更改web.config时在事件日志中看到的内容:
The description for Event ID 0 from source ASP.NET 2.0.50727.0 cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer. If the event originated on another computer, the display information had to be saved with the event. The following information was included with the event: _shutdownMessage=IIS configuration …
我编写了自己的Debugger Visualizer.
它和属性都在它们自己的程序集中.包含要调试的类的程序集中没有引用或属性 - 我想创建一个可供人们使用的drop-in dll.
我试图调试的类是通用的.
[Serializable]
public class FinCellTable<S> : IFinCellTable, IEnumerable<List<FinCell.IFinCell>>
where S : class, FinCell.IFinHeaderCell, FinCell.IFinCell, new()
Run Code Online (Sandbox Code Playgroud)
这是可视化工具:
[assembly: System.Diagnostics.DebuggerVisualizer(
typeof(Financials.Debugging.CellTableVisualizer),
typeof(VisualizerObjectSource),
Target = typeof(Financials.Transformation.IFinCellTable),
Description = "FinCell Table Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(
typeof(Financials.Debugging.CellTableVisualizer),
typeof(VisualizerObjectSource),
Target = typeof(Financials.Transformation.FinCellTable<Financials.FinCell.FinHeaderCell>),
Description = "FinCell Table Visualizer")]
namespace Financials.Debugging
{
public class CellTableVisualizer : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
{
if (windowService == null) throw new ArgumentNullException("windowService");
if (objectProvider == null) throw new ArgumentNullException("objectProvider");
var data = …
Run Code Online (Sandbox Code Playgroud) 因此,在我的应用程序中,用户将找到图像,有点像视频游戏中的概念艺术功能.我希望这些图像能够被缩放,共享和任何编辑 - 就像在图库应用程序中一样.展示它们的最佳方式是什么?我认为正确的方法是发送一个带有一个image/png类型的Intent.ACTION_VIEW,所以任何程序都可以得到它....
但在这种情况下,图像需要可供任何应用程序使用,它们不能成为资源,对吧?(因为那时他们不会被其他应用程序使用.)因此他们需要通过内容提供商提供...
我不认为我可以将它们粘贴在默认媒体内容提供商中......因为它们不会通过图库应用程序发现吗?我希望用户随着时间的推移"解锁"它们.所以我需要建立自己的内容提供商,并通过它发布图像,对吗?制作可以提供图像(以及视频,音频,可能是联系人或其他类型对象)的内容提供商的最佳方法是什么?
我想在所有方面匹配函数的特定参数可以为null。现在我正在使用
hasArgument(
3,
anyOf(
cxxNullPtrLiteralExpr()
,integerLiteral() // Technically this would alert on a constant pointer; but that's madness
)
)
Run Code Online (Sandbox Code Playgroud)
但是,这与以下代码不匹配:
void* nullObj = nullptr;
function(nullptr, false, false, nullObj);
Run Code Online (Sandbox Code Playgroud)
是否可以/容易地跟踪并匹配它?现在,我有一个非常简单的匹配器,但我想这种分析需要更多的逻辑吗?
我最近有必要动态地在javascript中重写javascript函数.我做的很容易,而且有多么有趣,让我很震惊.
在这里我有一些HTML:
<div id="excelExport1234"
onclick="if(somestuff) location.href='http://server/excelExport.aspx?id=56789&something=else'; else alert('not important');"
>Click here to export to excel</div>
Run Code Online (Sandbox Code Playgroud)
我无法更改输出的HTML,但我需要为该链接添加一个额外的参数.我开始考虑它,并意识到我可以这样做:
excelExport = $('excelExport1234');
if (needParam)
eval('excelExport.onclick = ' + excelExport.onclick.toString().replace("excelReport.aspx?id", "excelReport.aspx?extraParam=true&id") + ';');
else
eval('excelExport.onclick = ' + excelExport.onclick.toString().replace("extraParam=true&", "") + ';');
Run Code Online (Sandbox Code Playgroud)
它就像一个冠军!excelExport.onclick返回一个函数对象,我将其转换为字符串,然后执行一些字符串操作.由于它现在采用"function(){...}"的形式,我只需返回并将其分配给dom对象的onclick事件.不得不使用eval有点难看,但是AFAIK没有一个javascript函数构造函数可以接受一串代码并很好地将它变成一个对象.
无论如何,我的观点并不是我非常聪明(我不是),我的观点是这很酷.我知道javascript不是唯一可以做到这一点的语言.我听说过lisp为了这个目的已经有多年的宏了.除了真正的grok宏你需要真正grok lisp,我不会理解它,我只是'得到它'.
所以我的问题是:在其他语言中你能(轻松地)动态地重写函数,你能告诉我一个简单的例子吗? 我想看看你能做到的其他地方,以及它是如何完成的!
(另外,我不知道该怎么标记,所以我随机猜测)
我有大约30个500MB文件,每行一个字.我有一个脚本,用伪bash做到这一点:
for i in *; do
echo "" > everythingButI
for j in *-except-$i; do
cat $j >> everythingButI
sort everythingButI | uniq > tmp
mv tmp everythingButI
done
comm $i everythingButI -2 -3 > uniqueInI
percentUnique=$(wc -l uniqueInI) / $(wc -l $i) * 100
echo "$i is $percentUnique% Unique"
done
Run Code Online (Sandbox Code Playgroud)
它计算每个文件的"唯一性"(文件已经在每个文件中排序和唯一).
所以,如果我有文件:
file1 file2 file3
a b 1
c c c
d e e
f g
h
Run Code Online (Sandbox Code Playgroud)
file1将是75%唯一(因为其中1/4的行在另一个文件中找到),file2将是60%唯一,file3将是33.33%唯一.但是要把它变成30个文件,500MB一个弹出,需要一点点才能运行.
我想编写一个python脚本,它可以做得更快,更快,但我想知道实际上最快的算法是什么.(我在PC上也只有2GB的RAM.)
任何人都有关于算法的意见,或者知道更快的方法吗?