# What is wrong with this function

**URL:** <https://discourse.julialang.org/t/what-is-wrong-with-this-function/111500>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 12, 2024, 5:14am UTC](https://discourse.julialang.org/t/what-is-wrong-with-this-function/111500 "2024-03-12T05:14:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiang\_ming\_zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiang_ming_zhang/32/204063_2.png) [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Post date:** [March 12, 2024, 5:14am UTC](https://discourse.julialang.org/t/what-is-wrong-with-this-function/111500/1 "2024-03-12T05:14:26Z")

</div>

```julia
julia> function setBit{I<:Integer}(i::I,bit::Int64)
           return (i | (1 << (bit-1)))::I
       end
ERROR: UndefVarError: `setBit` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[1]:1

```

This function is from a github repository. The purpose apparently is to set some bit to 1.

where does the code go wrong?

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [March 12, 2024, 5:28am UTC](https://discourse.julialang.org/t/what-is-wrong-with-this-function/111500/2 "2024-03-12T05:28:03Z")

</div>

Normal functions in julia 1.0+ can not have type parameters in that position.  
only constructors for objects.  
IIRC there was a version of julia 0.x where they could but they worked like `where` clauses.

You probably intended:

```julia
julia> function setBit(i::I, bit::Int64) where {I<:Integer}
           return (i | (1<< (bit-1)))::I
       end
setBit (generic function with 1 method)

```

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [March 12, 2024, 6:45am UTC](https://discourse.julialang.org/t/what-is-wrong-with-this-function/111500/3 "2024-03-12T06:45:40Z")

</div>

> [@jiang\_ming\_zhang](#):
>
> ```julia
> julia> function setBit{I<:Integer}(i::I,bit::Int64)
> return (i | (1 << (bit-1)))::I
> end
> 
> ```

If you find code written before Julia 1.0 it can help to run it on an old version. Notice the helpful deprecation message.

```julia
$ juliaup add 0.7
Installing Julia 0.7.0+0.x64.linux.gnu
$ julia +0.7
               _
   _ _ _(_)_ | A fresh approach to technical computing
  (_) | (_) (_) | Documentation: https://docs.julialang.org
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 0.7.0 (2018-08-08 06:46 UTC)
 _/ |\ __'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-pc-linux-gnu

julia> function setBit{I<:Integer}(i::I,bit::Int64)
           return (i | (1 << (bit-1)))::I
       end
┌ Warning: Deprecated syntax `parametric method syntax setBit{I <: Integer}(i::I, bit::Int64)` around REPL[0]:2.
│ Use `setBit(i::I, bit::Int64) where I <: Integer` instead.
└ @ REPL[0]:2
setBit (generic function with 1 method)
```
