protocols

Can Clojure's protocol functions be variadic like ordinary functions?

末鹿安然 提交于 2020-01-28 08:57:46
问题 With clojure functions, I can define: (defn f [x & xs] (apply some-function x xs)) I'm attempting to do this same sort of thing with a protocol, e.g. (defprotocol foo (bar [f]) (baz [f & gs])) This compiles (at least in the REPL), but any implementing type seems to fail on this (the variadic, baz) method. Is this officially not supported? The sources that I've consulted are silent. 回答1: This is not supported, for the reasons Stuart Sierra gives. To go into a little more detail, the & symbol

Can Clojure's protocol functions be variadic like ordinary functions?

谁都会走 提交于 2020-01-28 08:55:48
问题 With clojure functions, I can define: (defn f [x & xs] (apply some-function x xs)) I'm attempting to do this same sort of thing with a protocol, e.g. (defprotocol foo (bar [f]) (baz [f & gs])) This compiles (at least in the REPL), but any implementing type seems to fail on this (the variadic, baz) method. Is this officially not supported? The sources that I've consulted are silent. 回答1: This is not supported, for the reasons Stuart Sierra gives. To go into a little more detail, the & symbol

why node js socket not working when change port to https?

不羁的心 提交于 2020-01-25 07:59:24
问题 Normally in app.js i use this code on port 3000 it's work good (on my-domain.com:3000 ). . http.listen(3000, function(){ console.log('start server on port :3000'); }); then i want to use on https , so i change app.js to http.listen(443, function(){ console.log('start server on port :443'); }); When run node app.js , it's show error events.js:160 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE :::443 at Object.exports._errnoException (util.js:1012:11) at exports.

How to make Swift protocol conformed by a specific kind of Class?

五迷三道 提交于 2020-01-25 07:28:07
问题 I wrote a protocol in Swift: protocol FooDelegate{ titleImage:UIImage? {get} } I want to make sure that the class that conforms to it must be a UITableViewController type. In other words: // ViewController conform FooDelegate is OK,Because ViewController // is inherit from UITableViewController! class ViewController:UITableViewController,FooDelegate /* compile ok */{ } // OtherVC is failed to conform FooDelegate,Because it is not inherit // from UITableViewController. class OtherVC

Overriding or extending UIColor to support certain protocols

南楼画角 提交于 2020-01-24 19:39:06
问题 I'm trying to subclass or extend UIColor to support a few protocols. Let's say my protocol looks like this: public protocol MyProtocol { init(myValue: Any) throws } For some reason, I'm unable to implement it, and I don't know why. This works for all other classes: class MyTestClass:SomeOtherClass, MyProtocol{ required init(myValue: Any) throws{ super.init(someOtherClassInitializer:Any) } } No issues. But if I try to do this with UIColor, I get errors. class MyColor:UIColor, MyProtocol{

Optional Protocol Requirements, I Can't Get It To Work

时间秒杀一切 提交于 2020-01-24 19:31:07
问题 I am working on one of the examples in The Swift Programming Language book related to Optional Protocol Requirements. I have a problem in the following code. import Foundation @objc protocol CounterDataSource { optional func incrementForCount(count: Int) -> Int optional var fixedIncrement: Int { get } } @objc class Counter { var count = 0 var dataSource: CounterDataSource? func increment() { if let amount = dataSource?.incrementForCount?(count) { count += amount } else if let amount =

Java: How to use byte literals greater than 0x7F

不问归期 提交于 2020-01-24 04:07:45
问题 In Java, I can't take a byte array of unsigned bytes (from something such as Wire Shark) and put this into java.... Because I will get compile errors since anything greater than 127 decimal/0x07F is treated not as a byte, but as an int.... IE: byte[] protocol = { 0x04, 0x01, 0x00, 0x50, /*error*/0xc1, /*error*/0xdb, 0x1c, /*error*/0x8c, 0x4d, 0x4f, 0x5a, 0x00 }; Need a good way to handle taking unsigned char arrays and putting them into Java as literals. 回答1: Cast them to (byte). 来源: https:/

How to read icy protocol in Java ?

自古美人都是妖i 提交于 2020-01-23 07:08:48
问题 I want to read data from a streaming icy protocol.The problem is that all the libraries that I've tried (dsj,MP3SPI) use the HttpUrlConnection to do this.However I've tried it on my windows 7 and I've received "Invalid http response" which is normal cause "HTTP 200 OK" is different from "ICY 200 OK".I know this could be accomplished with sockets but I'm a beginner so if any can provide a few lines o code so I can get an idea I would appreciate.Also if you have some solutions please share them

How to read icy protocol in Java ?

强颜欢笑 提交于 2020-01-23 07:08:06
问题 I want to read data from a streaming icy protocol.The problem is that all the libraries that I've tried (dsj,MP3SPI) use the HttpUrlConnection to do this.However I've tried it on my windows 7 and I've received "Invalid http response" which is normal cause "HTTP 200 OK" is different from "ICY 200 OK".I know this could be accomplished with sockets but I'm a beginner so if any can provide a few lines o code so I can get an idea I would appreciate.Also if you have some solutions please share them

Is it accurate to describe dispatch in Clojure using a Protocol as 'static'?

浪尽此生 提交于 2020-01-23 01:33:51
问题 Meikel Brandmeyer wrote a post on dispatch in Clojure with the URL title Static vs Dynamic. He writes: Protocols are not the only place where we have a trade-off of static vs. dynamic. There are several places where such a trade-off can be spotted. He provides the following example of static dispatch in a protocol: (defprotocol Flipable (flip [thing])) (defrecord Left [x]) (defrecord Right [x]) (extend-protocol Flipable Left (flip [this] (Right. (:x this))) Right (flip [this] (Left. (:x this)