syntax

What is this variable declaration with underscore, inline interface and assignment?

ぐ巨炮叔叔 提交于 2020-01-02 03:10:48
问题 What does this snippet of Go code do? var _ interface { add(string) error } = &watcher{} I believe &watcher{} returns two things, the first is discarded and the second is assigned to ... an interface? I found the code in fswatch on Github. 回答1: This construct will declare a variable with an blank identifier name with type given by a type literal; an interface definition in this case. What follows is in initializer expression - a pointer to a composite literal in this case. Overall

Is `export { foo as default }` valid ES2015?

混江龙づ霸主 提交于 2020-01-02 02:24:52
问题 I received an issue on GitHub about my ES2015 module import/export validating plugin for ESLint not recognizing the default export in the following syntax: export { foo as default, bar } where my plugin will lint the following (equivalent?) syntax no problem: export default foo; export const bar = ..; Both Babel and Esprima parse similar syntax without errors, and this works for code using Babel on both ends (import and export). However, I'm not convinced the spec allows the former export { x

How can I write-protect the Matlab language?

走远了吗. 提交于 2020-01-02 02:03:50
问题 Matlab allows you to overwrite built in functions without so much as a warning. For example, I've overwritten the function max() with a variable, but Matlab doesn't alert me to this. An error is only thrown later when the function is called, and doesn't help you see the actual problem: min = 0; max = 10; x = linspace(min,max,20); y = exp(x); disp(['the value is: ', num2str(max(y))]) Error message: Subscript indices must either be real positive integers or logicals. Is there a way to write

Getting “illegal use of explicit template arguments” when doing a pointer partial specialization for a class method

一世执手 提交于 2020-01-02 00:55:09
问题 Hello I'm having problems with partial specialization. What I want to do is have a class that has a template member function that will interpret a given value to one specified by the user. For instance the class name is Value and here is a snippet of what I want to do: int *ptr1 = new int; *ptr1 = 10; Value val1 = ptr1; int *ptr2 = val1.getValue<int*>(); Value val2 = 1; int testVal = val2.getValue<int>(); Here is how I implemented such class: struct Value { Value(void *p) : val1(p){} Value

What is this second new?

醉酒当歌 提交于 2020-01-02 00:49:09
问题 What is the second line? (Seen while answering another question.) int * x = new int [1] ; int * y = new (x) int; After the second line x and y have the same value (point to a same place). What's the difference between y = x and the second line? Is it like a constructor or something? 回答1: It's placement new. It constructs a new int in the memory pointed to by x . If you try: int * x = new int [1]; *x = 5; std::cout << *x << std::endl; int * y = new (x) int; *y = 7; std::cout << *x << std::endl

How do I write the qualified name of a symbol in Haskell?

六眼飞鱼酱① 提交于 2020-01-02 00:01:18
问题 I've got a name clash between two different Haskell modules that want to use the same infix operator ( <*> ). The Haskell 98 report says that modid.varsym is permitted, but I can't get it to work. In their entirety here are Test.hs : module Test where import qualified Test2 as T three = T.<*> and Test2.hs : module Test2 where (<*>) = 3 But trying to compile results in an error message: Test.hs:6:12: parse error on input `T.<*>' I tried T.(<*>) but that doesn't work either. How can I refer to

How to parse HL7 delimiters using only MS SQL Syntax

倾然丶 夕夏残阳落幕 提交于 2020-01-01 22:29:09
问题 Sharing this code that parses raw HL7 data using only MS SQL Syntax. It's a quick way of splitting all the | and ^ delimiters and store each data as a row. I wanted to share this because I've been looking around for way to parse HL7 Message strictly through SQL Syntax and was not able to find any resources. I would put it out there that this is not the most efficient method to import HL7 messages to SQL databases. There are other better methods (ie: C# app - HL7 > XML > DB, 3rd party software

Nodejs difference between 'res.json(..)' and 'return res.json(..)'

余生颓废 提交于 2020-01-01 19:50:48
问题 I am learning Nodejs and I do not fully understand the returns. For example, next() in many cases is suggested to be returned in order to make sure execution stop after triggering it (Reference). However, for cases like simple response, is return needed, what is the difference and what is preferred: res.json({ message: 'Invalid access token' }); vs. return res.json({ message: 'Invalid access token' }); 回答1: The return is used to stop execution. It is often used to do some form of early return

React JSX integration with erb and Ruby block syntax

我与影子孤独终老i 提交于 2020-01-01 18:02:13
问题 In my app/assets/javascripts/components/navbar.js.jsx.erb I can write something like this in the render function of my component (I'm using the gem react-rails): class Navbar extends React.Component { render() { return( <div className="navbar-header"> <ul> <li> <%= link_to root_path, className: 'navbar-brand' do %> <span className='glyphicon glyphicon-home'></span>   <%= I18n.t('menu.now') %> <% end %> </li> <li><%= link_to I18n.t('menu.archive'), archive_path%></li> </ul> </div> ); } } All

Why django has to use double underscore when making filter queries?

妖精的绣舞 提交于 2020-01-01 11:55:08
问题 So in django we write Entry.objects.filter(blog__id=3) Which looks ugly because sometimes there are too many underscores Entry.objects.filter(blog_something_ underscore _too_ many _id=3) why django can't use syntax like [entry.objects if blog.id=3 ] ? I am not expert on this, but why must double underscore? Could there be a more elegant style in python's grammar to write this? 回答1: Django runs on Python, which sets some basic constraints when it comes to syntax, making the following suggested